1. What is inheritance in Java?
2. In Java, which keyword is used to implement inheritance between classes?
3. What is a superclass in Java?
4. In Java, can a subclass inherit constructors from its superclass?
5. What is method overriding in Java?
6. In Java, can a subclass override a private method from its superclass?
7. What is the "super" keyword used for in Java?
8. What is the result of the following code snippet?
class Parent {
void display() {
System.out.println("Parent");
}
}
class Child extends Parent {
void display() {
System.out.println("Child");
}
}
public class Main {
public static void main(String[] args) {
Parent obj = new Child();
obj.display();
}
}
class Parent {
void display() {
System.out.println("Parent");
}
}
class Child extends Parent {
void display() {
System.out.println("Child");
}
}
public class Main {
public static void main(String[] args) {
Parent obj = new Child();
obj.display();
}
}