What is the result of the following code snippet?
class Parent {
protected void display() {
System.out.println("Parent");
}
}
class Child extends Parent {
void show() {
display();
}
}
public class Main {
public static void main(String[] args) {
Child obj = new Child();
obj.show();
}
}
protected void display() {
System.out.println("Parent");
}
}
class Child extends Parent {
void show() {
display();
}
}
public class Main {
public static void main(String[] args) {
Child obj = new Child();
obj.show();
}
}
A. Compilation error
B. Runtime exception
C. Child
D. Parent
Answer: Option D

Join The Discussion