i'm trying in this question to resolve this problem. When referencing a child class using a parent class reference, we call the parent class's methods.
class Programmer {
void print() {
System.out.println("Programmer - Mala Gupta");
}
}
class Author extends Programmer {
void print() {
System.out.println("Author - Mala Gupta");
}
}
class TestEJava {
Programmer a = new Programmer();
Programmer b = new Author();
b.print();
}
Following this code, I get the output like this 'Author - Mala Gupta'; despite that I should get the parent's method executed. Can you explain to me what's happening behind the scenes.