How to call parent class method from child class object in Java
Save below program in Main.java file
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Save below program in Main.java file
class ParentClass {
public void printParent() {
System.out.println("Calling parent class method...");
}
}
class ChildClass extends ParentClass {
public void printChild() {
System.out.println("Calling child class method...");
}
}
public class Main {
public static void main(String[] args) {
ChildClass childClass = new ChildClass();
childClass.printParent();
}
}
Compile program javac Main.java
Run program java Main
Output Calling parent class method...
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Comments
Post a Comment