Single Choice
Not Set
QWhat 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();
}
}
ID: #2269
Inheritance in Java MCQ
2,182 views
Question Info
#2269Q ID
Not SetDifficulty
Inheritance in Java MCQTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer
Explanation
ClassCastException exception is thrown at runtime.
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic