Hi Friends,
I have an idea about this question.Please be patient and read the answer.
The answer is definitely 3.
As one of our friends specified we are declaring and initializing the private instance variable at the same line.
private int i = giveMeJ();
which is equilant to
private int i;
i = giveMeJ();
Even though the instance variable i is declared private ,we can access it in the main method of the same class.But if we copy and paste the same main method in another class (which may extend the AQuestion class or any other class) we will get a compile error.We cannot access private variables outside the class in which it is declared.
And coming to the output.
It is 0 instead of 10 as we expect .
Because by the time the line
private int i = giveMeJ(); is executed j is not initialized to 10.So the method giveMeJ returns 0 which is default value for an int.
If we just interchange the two lines we will get 10 as output.
private int j = 10;
private int i = giveMeJ();
Here j is initialised before the giveMej() is executed .So we get 10 as output.
This is what I think about the question.If u have any new ideas please let me know.
My mail id is
[email protected] Thanking you,
Muraleedhar Nelakonda