Hello Raja,
b1.toString()==b1.toString() will return false as both the statements will return new string objects and when you compare two different string objects using == it will return false.
Now coming to the case of declaring "int i=10" or "i=10" in the static block:
When you give the print statements:
System.out.println(b.i); OR
System.out.println(i);
Both the statements is trying to print the same class variable i. The variable i is first intialized by 20 and then modifies in the static block by 10(when you use simply "i=10"). So it will print the last value assigned to i i.e. 10.
Now, when you use "int i=10", in that case there are two variable named i one is class variable and one is local to the static block and in the print statements you are printing the class variable i and its value is 20,so it will print 20.
I hope it will help.
Regards
Gurpreet Sachdeva
For Mock Exams, FAQ and some useful information about Bitshift operator, inner classes, garbage collection,etc please visit:
http://www.go4java.20m.com
Regards<BR>Gurpreet Sachdeva<P>For Mock Exams, FAQ, Exam tips and some useful information about Bitshift operator, inner classes, garbage collection,etc please visit: <A HREF="http://www.go4java.lookscool.com" TARGET=_blank rel="nofollow">http://www.go4java.lookscool.com</A>