Yaa, Field variables are not overriding, there are hiding. OK, Here I have problem with, how the method toString() returns Good Bye rather than How are you ? This thing, I couldn't understand! Please Explain! Thanks in Advanced!
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
is invoked on obj reference which is of type AB but refers to actual object instance of type BA which is a subtype of the former. As the subtype has got the toString method overriden in the BA subclass this is what gets called at runtime. That's why you can see the output Good Bye which greeting instance variable of BA is initialized to and is not changed ever after.