Junior
How to access overridden methods of a parent class in Java?
sobes.tech AI
Answer from AI
Access to overridden methods of the parent class is done using the super keyword.
class Parent {
public void display() {
System.out.println("Method from parent class Parent");
}
}
class Child extends Parent {
@Override
public void display() {
// Call the overridden method of the parent class
super.display();
System.out.println("Method from child class Child");
}
public void invokeParentMethod() {
// Another way to call the parent class's overridden method
super.display();
}
}