This program implements constructor chaining. Comment below. Have fun!!!
//cannot use this and super in same constructor
class X
{
public X(int i)
{
}
}
class Y extends X
{
public Y(int i)
{
super(i);
}
}
class Z extends Y
{
public Z(int i)
{
super(10);
}
}
class ChainDemo
{
public static void main(String[] args)
{
Z ob = new Z(10);
}
}
//finalise with object to force garbage collection
No comments:
Post a Comment