Java Program to explain Super Keyword, write a program in java using super keyword through extend class of class inheritance
Programclass base
{
int i;
base(int a)
{
i=a;
}
void show()
{
System.out.println("Base:"+i);
}
}
class derived extends base
{
int i,j;
derived(int a,int b,int c)
{
super(a);
i=b;
j=c;
}
void show()
{
super.show();
System.out.println("Base i:"+super.i);
System.out.println("Derived i:"+i);
System.out.println("Derived j:"+i);
}
}
class superEx
{
public static void main(String args[])
{
derived d = new derived(10,20,30);
d.show();
}
}
No comments:
Post a Comment