Q. What is the result of the following code snippet?
class Parent {
private 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();
}
}
β
Correct Answer: (B)
10 20
Explanation: The given code snippet involves inheritance in Java. It defines two classes: Parent and Child. The Child class extends the Parent class, which means it inherits its fields and methods.