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
Get step-by-step solutions from verified subject matter experts
