Question: 2 . What will the following Java code output? / / Example 2 class Parent { public void display ( ) { System.out.println (

2. What will the following Java code output?
// Example 2
class Parent {
public void display(){
System.out.println("Parent class method");
}
}
class Child extends Parent {
@Override
public void display(){
System.out.println("Child class method");
}
}
public class Main {
public static void main(String[] args){
Parent obj;
if (args.length >0){
obj = new Child();
} else {
obj = new Parent();
}
obj.display();
}
}
B) Child class method
D) Runtime Error
C) Compilation Error
A) Parent class method

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 Programming Questions!