Henry Wong wrote:
Keep in mind that inherited doesn't mean that the sub class gets a copy of the method, it calls the super's version of the method.
And in the Exam class -- the display() method is part of that class; compiled with the class; and from the point of that method, the "this" reference is of type Exam. And since polymorphism doesn't apply to instance variables, it will get the Exam version.
Henry
An excellent answer! This made the concept quite clear to me.
Now if what you say is true then it implies that if I overide the display() method in
Scjp class and run the same program again then the output should be "Killing".
This is because:
-> calling display() will actually now call this.display()
-> since this.display() has been compiled with scjp class it will call this.difficultLevel
-> meaning that this.difficultyLevel should be printed.
I'll verify this once I reach home and have access to my pc. I'll post my findings in this
thread. hehe
