Program:Here is the Example of Calling Super class parametrized constructor from Sub class.
class Super
{
int i;
Super(int i)
{
this.i=i;
}
}
class Sub extends Super
{
int i;
Sub(int a,int b)
{
super(a); //call super class constructor and pass a
i=b;
}
void show()
{
System.out.println("Sub class i = "+i);
System.out.println("Super class i = "+super.i);
}
}
class Result
{
public static void main(String args[])
{
Sub s=new Sub(15,32);
s.show();
}
}
O/P:
Sub class i = 32
Super class i=15
No comments:
Post a Comment