单选题:Java程序阅读关于继承和多态
有以下Java程序,请问最后的t.printValue(10)会调用哪一个方法?(选择注释中编号)
class Person {
public void printValue(int i, int j) { } //1
public void printValue(int i){ } //2
}
public class Teacher extends Person {
public void printValue() { } //3
public void printValue(int i) {} //4
public static void main(String args[]){
Person t = new Teacher();
t.printValue(10);
}
}
A.1
B.2
C.3
D.4
answer:D
class Person {
public void printValue(int i, int j) { } //1
public void printValue(int i){ } //2
}
public class Teacher extends Person {
public void printValue() { } //3
public void printValue(int i) {} //4
public static void main(String args[]){
Person t = new Teacher();
t.printValue(10);
}
}
A.1
B.2
C.3
D.4
answer:D