topic description
class Super{
private String name = "Super";
public String getName() {
return this.name;
}
}
public class Sub extends Super{
private String name = "Sub";
public static void main(String[] args) {
Sub sub = new Sub();
//Super
System.out.println(sub.getName());
}
}
what result do you expect? What is the error message actually seen?
I thought I would output sub, but I actually output super. I always thought that this refers to the caller of the method, getName () is called by sub, so the this should be sub, then the sub.name should be sub;, but this is obviously wrong