Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super. The second is
used to access a member of the superclass that has been hidden by a member of a subclass.
Here is the source code of the Java Program to Access the Super Class Method and Instance Variable Using Super Keyword from Sub Class. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
int x = 5;
System.out.println("Method of parent class using Super Keyword");
class Child extends Parent
int x = 9;
System.out.println("Instance Variable of Parent class using Super Keyword :"+super.x);
System.out.println("Instance variable of Child class :"+x);
System.out.println("Method of Child class ");
public static void main(String... a)
Child ob = new Child();
$ javac Child.java $ java Child Instance Variable of Parent class using Super Keyword :5 Instance variable of Child class :9 Method of parent class using Super Keyword Method of Child class
Sanfoundry Global Education & Learning Series – 1000 Java Programs.