Wednesday, April 23, 2014

super() example

It’s legal to invoke "new" from within a constructor and  to call
super() on a class with no explicit superclass.

public class Test1 {

static int count = 0;

Test1() {
while(count < 10)
new Test1(++count);
}

Test1(int x)
{
super();
}

public static void main(String[] args) {
new Test1();
new Test1(count);
System.out.println(count++);
}

}


outcome is 10 here.


No comments:

Post a Comment