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...

The Save button is located on the Quick Access Toolbar

Indicate whether the statement is true or false

Computer Science & Information Technology

Individual array elements can be displayed using the ___________________ object.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

The value assigned to the cite attribute of is rendered by a browser or visible in a ToolTip.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Types of e-commerce

What will be an ideal response?

Computer Science & Information Technology