This is a Java Program to Use Super Keyword in Inheritance Class.
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.
class Base
{
int x = 19;
}
class Child extends Base
{
int x = 20;
void shows()
{
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();
obj.shows();
}
}
Output:
$ 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.
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Check Programming Books
- Apply for Computer Science Internship
- Practice BCA MCQs
- Check Java Books
- Practice Information Technology MCQs