Given the following code for a Car class with methods start and brake, which of the following is legal?

```cpp
Car *car;
Car car2;
car2→start();
// ();
car→brake();
car2.brake();
```

A. `car2→start();`

B. `();`

C. `car→brake();`

D. `car2.brake();`

Answer :

Final answer:

The legal ways to call the methods start and brake of the car class are car2.start(); and car.brake();.

Explanation:

The legal ways to call the methods start and brake of the car class are:

  1. car2.start();
  2. car.brake();

The other options are not legal:

  • A. car2→start(); - Invalid syntax. Use the dot operator (.) instead of the arrow operator (->).
  • B. (); - Invalid syntax. Calling a method requires an object instance or class name followed by the dot operator (.)
  • C. car→brake(); - Invalid syntax. Use the dot operator (.) instead of the arrow operator (->).
  • D. car2.brake(); - Invalid syntax. Use the dot operator (.) instead of the arrow operator (->).