there is this great set of 80 questions posted by abhilash...
i thot i was pretty prepared but am all rubbery knees now!
i ahve just tried the first 20 and faltered on many. there are 2 i can't resolve... please help!
1.)
Read this piece of code carefully
if("
String ".trim() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
Answers
1.the code will compile an print "Equal".
2.the code will compile an print "Not Equal".
3.the code will cause a compiler error
the answer is2. but it says for trim....
"If this String object represents an empty character sequence, or the first and last characters of character sequence represented by this String object both have codes greater than '\u0020' (the space character), then a reference to this String object is returned.Otherwise, if there is no character with a code greater than '\u0020' in the string, then a new String object representing an empty string is created and returned."
Please help....
the next problem is.....
2.)
public class AQuestion
{
private int i = giveMeJ();
private int j = 10;
private int giveMeJ()
{
return j;
}
public static void main(String args[])
{
System.out.println((new AQuestion()).i);
}
}
Answers
1.Compiler error complaining about access restriction of private variables of AQuestion.
2.Compiler error complaining about forward referencing.
3.No Compilation error - The output is 0;
4.No Compilation error - The output is 10;
The answer is 3. what happens???