Hi, I guess its false, At the most u can make an object 'eligible' for g/c.But whether/when the object will be g/c'd is the prerogative of the jvm and not the programmer. Plz. correct me if i am wrong.
// IncTest.java public class IncTest { int i=3,k=0; public void SomeMethod (){ k= ++i * ++i * ++i ; System.out.println("i = "+i +"k= "+k); } public static void main (String args[]){ IncTest obj = new IncTest(); obj.SomeMethod(); } } _________________________________ output i = 6 k= 120 ------------------------ //IncTest.c++ #include<iostream.h> void main(){ int i = 3 , k=0 ; k = ++i * ++i * ++i ; cout << "i = "<< i; cout << "k = "<< k; } __________________________________________________ output : i = 6 k = 216 The second o/p seems obvious since the precedence of '++' is higher than '* ' so first 'i' is incremented to 6 & then 6 * 6 * 6 is 216. Then why is is o/p in IncTest.java different.
Thanks guys ! That did solve my second querry , but @ the first I wud like to know what forms the basis of the C'tor A(int i) in class A being invoked & not A (). ( A () is invoked by A(int i) thru this() )
int f() { System.out.println("B.f called"); return 47; } }
public class CtorDemo { public static void main(String args[]) { B bobj = new B(); } } 1 . Why does the C'tor A(int) get preference over A() in class A while B() over B(int) in class B ? 2 . Also if I use this() in A() instead of A(int) C'tor (or in B(int) instead of B()) i get "Recursive constructor invocation" error , plz clarify my this() funda .