Consider a class hierarchy that includes a class called Vehicle, with subclasses called Car and Airplane. The Vehicle class has a method called getMaxSpeed, which is overridden in the Car class. The getMaxSpeed of the Vehicle class returns 760 mph, while the getMaxSpeed method of the Car class is overridden to return 150 mph. What is the output of the following snippet of code? Explain your answer.
What will be an ideal response?
```
Vehicle v = new Car();
System.out.println(v.getMaxSpeed() + “ mph”);
```
The output of this code will be “150 mph”. Even though the reference is to the Vehicle class, the
getMaxSpeed method is bound to the definition in the Car class, since the object is a car. This is due to the polymorphic
nature of the reference.
Computer Science & Information Technology
You might also like to view...
What can a technician do if a display has bright spots?
A) Update the driver. B) Replace the display. C) Decrease the refresh rate. D) Lower the resolution.
Computer Science & Information Technology
A standard BD has a capacity of ____ GB per layer.
A. 15 B. 20 C. 25 D. 30
Computer Science & Information Technology