In this question, the output is given as Rose0. But when I look through the logic, I believe that the answer should be Rose100 instead of Rose0. How the compiler distinguishes I s in both classes. Since Rosea extends the _39 class, it also has a super i class. But on line 1, if I change super.i, then Im will get Rose100. How is that different?
class _39 {
int i;
_39(){
i=100;
foo();
}
public void foo(){
System.out.println("Flower"+i);}
}
}
public class Rosea extends _39{
int i=200;
Rosea(){
i=300;
}
public void foo(){
System.out.println("Rose"+i);
}
public static void main(String[] args) {
new Rosea();
}
}
user2445123
source
share