Question: The following classes are defined in separate files. What will be the output when the class Test will run? Explain briefly. class Vehicle { public

The following classes are defined in separate files. What will be the output when the class Test will run? Explain briefly.

class Vehicle { public void drive() { System.out.println("Vehicle: drive"); } } class Car extends Vehicle {

public void drive() { System.out.println("Car: drive"); } } public class TestSubClasses { public static void main (String args []) { Vehicle v; Car c; v = new Vehicle(); c = new Car(); v.drive(); c.drive(); v = c; v.drive(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!