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. }


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

Sanfoundry Global Education & Learning Series – 1000 Java Programs.


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

Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn