 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
vinlore Guest
|
Posted: Thu Nov 25, 2004 12:32 am Post subject: NEWBIE HELP: Super class accessing attributes of sub-class |
|
|
I have a sub class, subClass1 that has a protected attribute, subAtt. The
sub class uses super() in the constructor. If I instantiate the super
class, why can't I see the subAtt attribute ?
|
|
| Back to top |
|
 |
Hal Rosser Guest
|
Posted: Thu Nov 25, 2004 2:27 am Post subject: Re: NEWBIE HELP: Super class accessing attributes of sub-cla |
|
|
"vinlore" <vinlore (AT) nospam (DOT) msn.com> wrote
| Quote: | I have a sub class, subClass1 that has a protected attribute, subAtt. The
sub class uses super() in the constructor. If I instantiate the super
class, why can't I see the subAtt attribute ?
|
Because the sub class "is a" super class - but a super class isn't
necessarily a sub.
Consider
A Class Pet, and a class Dog which extends Pet, and a class Cat which
extends Pet, a Parrot class the extends Pet, etc - any number of different
classes that extends Pet...
a Dog instance 'is a' Pet
but
a Pet instance could be a fish, a cat, or Parrot.
If you cast the Pet to a Dog, then you may be able to call your method.
HTH
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ([url]http://www.grisoft.com)[/url].
Version: 6.0.799 / Virus Database: 543 - Release Date: 11/19/2004
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|