below java code is not compiling showing error message.
Object obj=new Object(); //here I have tried to test with other class as well but result is same code is showing error message.
while if add curly bracket to if condition like below code working fine.
Object obj=new Object();
can anybody please explain the above difference.
Edited by: user12152025 on Aug 18, 2012 10:20 AM
The defect is in your code. The code the compiler rejects is illegal, because a declaration is not a statement, and the syntax of 'if' says that it can only be followed by a statement. It is also completely pointless, because the object being declared falls out of scope immediately.