Gauri Savanur

Greenhorn
+ Follow
since Apr 25, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Gauri Savanur

Congratulations!!
20 years ago
The reason for outputting 61433 is that it's "OR" condition.
So even though "x != 3" becomes false when value of x=3, being "OR" condition it will check for second condition "success < 2" which is true as the value of success is "0". So it goes again in the loop prints 3, increments the value of success which is "1" still the condition is true so it again goes inside the loop prints "3" again increments the value of success which is now "2". Now the condition "success < 2" is false as value of success is "2".
Since both the "OR" conditions are false it will come out of the loop.
Hope I clarify your doubt.
Static and overloaded method invokation is decided at compile time and not at run time.
So even if the object is of subclass type, the method invokation is dependent on reference.
Today I passed SCJP1.4 with 90%.
I used Rober Heler and K&B. K&B is a really good book for certification.
Read it for a week and I could score 90%.
Actual exam was not very difficult as I thought of.
Solve as many mock exams as u can.
20 years ago
Thanks a lot for all your replies.
To summarize,
In toString() always the same reference as the original string is returned. So comparison with toString will always be true.
For trim() and subString() if the same string is returned as the original one then original String reference is returned.
The code seems to be perfectly legal.
Because if u are not implementing the method of the interface in the implementing class then u have to declare it abstract. Since the implementing class is declared as abstract it will compile.
The code will also run and give the output 1 because abstract class can be run as a standalone program. Just u can't create instance of it. Trying to create the instance will give u compilation error.
Is it really giving you compilation error? Becasue when I tried to compile it, there were no compilation error and output shown as "inside the innertest method of InnerClass test".
I don't think there is any problem in the code.
If the code mentioned below is run "true, true, true" is displayed.
If the strings are immutable then different instances of String objects will be created on each of the call of s0.trim() etc.
Why the comparison is same even if the references are different?
public class Test012
{
public static void main(String args[])
{
String s0 = new String("Java");
String s1 = s0.trim();
String s2 = s0.substring(0, 4);
String s3 = s0.toString();
System.out.println(s0 == s1);
System.out.println(s0 == s2);
System.out.println(s0 == s3);
}
}