Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super.We made two same data member in base and child class and we call the base class data member from child class by using Super Keyword.
Here is the source code of the Java Program to Use Super Keyword in Inheritance Class. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
int x = 19;
class Child extends Base
int x = 20;
System.out.println("The base class data member (x) by Super Keyword :" + super.x);
System.out.println("The child class data member :" + x);
public static void main(String... a)
Child obj = new Child();
$ javac Child.java $ java Child The base class data member (x)by Super Keyword :19 The child class data member :20
Sanfoundry Global Education & Learning Series – 1000 Java Programs.