What will be the Output of this Program?
class P
{
int z=2;
P()
{
System.out.println("Default");
}
P(int x)
{
this();
System.out.println("one argument");
}
P(int m, int n)
{
this(z);
System.out.println("Argumented");
}
public static void main(String arr[])
{
P p = new P(1, 2);
}
}
class P
{
int z=2;
P()
{
System.out.println("Default");
}
P(int x)
{
this();
System.out.println("one argument");
}
P(int m, int n)
{
this(z);
System.out.println("Argumented");
}
public static void main(String arr[])
{
P p = new P(1, 2);
}
}
This comment has been removed by the author.
ReplyDeleteWe cannot use any instance variable of the construtor's class in a call to this()
DeleteU right,
Deletebt if z is static it can be called :P
Anjali: If z is static then it will not be a instance variable. :P
Deleteif we use this(n) instead of this(z) is it ok
Delete