Sail E0 Webinar
Question
What will be the result of compiling and executing the following program code?class Vehicle{ public void printSound(){ System.out.print("vehicle"); }}class Car extends Vehicle{ public void printSound(){ System.out.print("car"); }}class Bike extends Vehicle{ public void printSound(){ System.out.print("bike"); }}public class Test{ public static void main(String[] args){ Vehicle v = new Car(); Bike b = (Bike) v; v.printSound(); b.printSound(); }}
Options:
A .  "carcar" is printed.
B .  Compilation fails.
C .  ClassCastException exception is thrown at runtime.
D .  "vehiclebike" is printed.
E .  "vehiclecar" is printed.
Answer: Option C

Submit Your Solution Below and Earn Points !
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers