Inheritance and Static Variables
What is the output when the above code is executed?
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();
}
}
A
Child: 20
Parent: 20
B
Child: 20
Parent: 10
C
Child: 10
Parent: 20
D
Child: 10
Parent: 10
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE