Inheritance With Private Methods
Consider the following class declarations. What is printed as a result of executing the main method?
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
Parent secret
Child secret
B
Compilation Error
C
Child secret
D
Parent secret
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | ahsan48105 | 2 | 2 | 0m 00s | 200 |
| #2 | kwsmith | 2 | 2 | 0m 00s | 200 |
| #3 | billminhhanguyen | 2 | 2 | 1m 23s | 117 |
Items per page:
10
1 – 3 of 3
