Inheritance and Static Variables
Consider the following class declarations.
public class Parent {
public static int value = 10;
}
public class Child extends Parent {
public static int value = 20;
public void printValues() {
System.out.println("Child: " + value);
System.out.println("Parent: " + super.value);
}
}
public class Main {
public static void main(String[] args) {
new Child().printValues();
}
}
What is printed when the main method of the Main class is executed?
A
Child: 10
Parent: 20
B
Child: 20
Parent: 10
C
Child: 20
Parent: 20
D
Child: 10
Parent: 10
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE