Friday, February 4, 2011

super keyword

//using "super" we can call super class metods in sub class by using sub class obj
class One
{
int x;
One(int x)
{
this.x=x;
}
void show()
{
System.out.println("Super :x"+x);
}
}

class Two extends One
{
int x;
Two(int a,int b)
{
super(a); //calling super class variables
x=b;
}
void show()
{
System.out.println("Sub x---"+x);
super.show(); // calling super class method
}
};

class Super
{
public static void main(String[] args)
{
Two t=new Two(10,15);
t.show();
}
}

No comments:

Post a Comment