Its Natural that the above program is giving excpetion.. (java.lang.NoSuchMethodError: main) as in the program class a is public. and class cc is having default modifier.

And we have written main method in a. Thats why the exception is thrown. As we says $>java a, compiler searches for main method in a. if we call the same $>java cc It gives result as inside b's arg constructor

Hi friends: While running the Rajesh's code I am also getting the output as "inside b's arg constructor" But what about new B() statement inside A(int i) constructor??? Why it's not again going inside B's constructor?? I am marking that line as //2 in my code.

Also,when I am trying to run it without any parameter...it's not printing anything. Why it's not printing "inside b's constructor" ???Is it not going inside A() followed by B()???

Originally posted by Swapnil Trivedi: Hi friends: While running the Rajesh's code I am also getting the output as "inside b's arg constructor" But what about new B() statement inside A(int i) constructor??? Why it's not again going inside B's constructor?? I am marking that line as //2 in my code.

It is going inside B's constructor from line marked as //2... In fact this is the only line of code causing the B's constructor to be called...

Originally posted by Swapnil Trivedi:

Also,when I am trying to run it without any parameter...it's not printing anything. Why it's not printing "inside b's constructor" ???Is it not going inside A() followed by B()???