What is the result of the following code snippet?
class Parent {
int x = 10;
}
class Child extends Parent {
int x = 20;
void display() {
System.out.println(super.x + " " + x);
}
}
public class Main {
public static void main(String[] args) {
Child obj = new Child();
obj.display();
}
}
int x = 10;
}
class Child extends Parent {
int x = 20;
void display() {
System.out.println(super.x + " " + x);
}
}
public class Main {
public static void main(String[] args) {
Child obj = new Child();
obj.display();
}
}
A. Runtime exception
B. Compilation error
C. 20 10
D. 10 20
Answer: Option D
Join The Discussion