I couldn't grasp the idea why the codes below prints console Person twice. I thought it should have been Person and Student. When getInfo() inside printPerson() is called through "a" object, why is the one inside Person class being invoked and why is the one in the Student class not invoked? Thanks in advance.
class deneme{
public static void main(String[] args) {
Person b = new Person();
b.printPerson();
Student a = new Student();
a.printPerson();
}
}
class Student extends Person {
public String getInfo() {
return "Student";
}
}
class Person{
private String getInfo() {
return "Person";
}
public void printPerson() {
System.out.println(getInfo());
}
}