You are here: Home / Topics / Program to explain Calling super class parameterize constructor using super in Java

Program to explain Calling super class parameterize constructor using super in Java

Filed under: Java on 2023-09-17 07:08:12

// Program to explain Calling super class parameterize constructor using super.

class  A 
{
int x;

A(int a) 
{
 x = a;
 System.out.println("A constructor, x : " + x);
}
}

class  B extends A 
{
int y;

B(int a, int b) 
{
 super(a);
 y = b;
 System.out.println("B constructor, y : " + y);
}
}

class  C extends B 
{
int z;

C(int a, int b, int c) 
{
 super(a, b);
 z = c;
 System.out.println("C constructor, z : " + z);
}
}

public class  InheritanceConstructor4 
{
public static void main(String[ ] args) 
{
 C x = new C(10, 20, 30);
}
}


Output:

A constructor, x : 10
B constructor, y : 20
C constructor, z : 30

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