Hi,
Just trying to improve my understanding of inheritance and access to a super class's variable, I wrote 3 classes and came across something I do not understand. It seems that if a class refers to its super's variable explicitly, via super., then later use of that variable's name continues to refer to the super's variable, even without the 'super.'.
If no 'super.' is ever used, reference is to the sub-class's copy ... ?
Any ideas where I'm getting this wrong would be appreciated.
Here's the code & output:
-------------------------------------
-------------------------------------------
---------------------------------------------
-----------------------------------------------------
-----------------------------------------------------
Output:
new Junk starting
junk Constructor says b equals 5
junkSay says b equals 5
new TJ1 starting
junk Constructor says b equals 5
null says entered Constructor now
TJ1 says exiting Constructor now
TJ1 says added 100 to super.b: 105
junkSay says b equals 105
TJ1 says added 1 to my b: 106
junkSay says b equals 106
new TJ2 starting
junk Constructor says b equals 5
null says entered Constructor now
TJ2 says exiting Constructor now
TJ2 says not added 100 to super.b: 5
junkSay says b equals 5
TJ2 says added 1 to my b: 6
junkSay says b equals 6
-----------------------------------------------
[edit]Add code tags. CR[/edit]
[ January 01, 2009: Message edited by: Campbell Ritchie ]