Java Program to Access Super Class in a Method Overriding

«
»
This is a Java Program to Access Super Class in a Method Overriding.

Here we made get() method in both base and child class. Child class override the method of base class and to run both methods we use the Super keyword.

Here is the source code of the Java Program to Access Super Class in a Method Overriding. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

  1. class Base
  2. {
  3.     void get()
  4.     {
  5.         System.out.println(" Base class method via Super keyword");
  6.     }
  7. }
  8. class Child extends Base
  9. {
  10.     void get()
  11.     {
  12.        super.get();
  13.        System.out.println("Child class method");
  14.     }
  15.     public static void main(String... a)
  16.     {
  17.        Child obj1 = new Child();
  18.        obj1.get();
  19.     }
  20. }

Output:

$ javac Child.java
$ java Child
 
Base class method via Super keyword
Child class method

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.