This is a question from Jaworski Quiz :
What is the output of the following program ?
----------------------------------------------------------------
class Question{
String s ="Outer";
public static void main(String[] args){
S2 s2 = new S2();
s2.display();
}
}
class S1{
String s ="S1";
void display(){
System.out.println(s);
}
}
class S2 extends S1 {
String s ="S2";
}
A.S1
B.S2
C.null
D.S1S2
I thought the program would output S2, by using the inherited dispaly method from S1 to display its won s variable, which I thought hides the s variable in S1.Apparently the correct answer is, A, the display method displays the s variable of the S1 class. I dont understand. Anyone can educate me.
Thanks,
Herbert.