public class Test1{
String name = "Test1";
String getName(){
return name;
}
}
public class Test2 extends Test1{
String name = "Test2";
}
public class Test {
public static void main(String[] args) {
Test2 t = new Test2();
System.out.println(t.getName());
}
}
Why t.getName() returns "Test1". If that's the case, getName() cannot be inherited properly because the inheritance method getName() will always trace the name in super class, which is not applicable. Am I right?