Question 11.
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;
Correct answer is 3.
Can anyone please explain me the above answer? How does J get initialized?
Thanks,
Snehal
[This message has been edited by snehal shah (edited January 24, 2001).]