You are here: Home / Topics / Using super keyword to call Overriding Method example in Java

Using super keyword to call Overriding Method example in Java

Filed under: Java on 2023-09-17 07:01:22

//  Using super to call Overriding Method.

class  A 
{
int  i, j;

A(int a, int b) 
{
 i = a;
 j = b;
}

void show() 
{
 System.out.println("i and j: " + i + " " + j);
}
}

class B extends A 
{
int k;

B(int a, int b, int c) 
{
 super(a, b);
 k = c;
}

void show() 
{
 super.show();
 System.out.println("k: " + k);
}
}

class  MethodOverriding1 
{
public static void main(String args[ ]) 
{
 B subOb = new B(1, 2, 3);

 subOb.show();   // this calls show() in B
}
}

 

Output:

i  and  j: 1  2
k: 3

About Author:
S
Shyam Dubey     View Profile
If you are good in any field. Just share your knowledge with others.