Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2004

Tip: Looking for answers? Try searching our database.

NEWBIE HELP: Super class accessing attributes of sub-class

Thread view: 
vinlore - 25 Nov 2004 00:32 GMT
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 ?
Hal Rosser - 25 Nov 2004 02:27 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.