Static Method Hiding Instance Method
Given the following class declarations, what is the result of an attempt to compile and execute the main method in the Child class?
class Parent {
public void display() {
System.out.print("Parent ");
}
}
class Child extends Parent {
public static void display() {
System.out.print("Child ");
}
public static void main(String[] args) {
Parent p = new Child();
p.display();
}
}
A
No output
B
Compilation Error due to static method hiding an instance method
C
Child
D
Parent Child
Question Leaderboard
Not enough data yet to show leaderboard.
