Inheritance With Private Methods
What is the output when the main() method is executed?
public class Parent {
private void secret() {
System.out.println("Parent secret");
}
public void reveal() {
secret();
}
}
public class Child extends Parent {
private void secret() {
System.out.println("Child secret");
}
}
public class Main {
public static void main(String[] args) {
Parent p = new Child();
p.reveal();
}
}
A
Child secret
B
Compilation Error
C
Parent secret
D
Parent secret
Child secret
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE