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 / General / February 2006

Tip: Looking for answers? Try searching our database.

subclass has a variable that is subclass of same superclass

Thread view: 
jstorta - 19 Feb 2006 20:42 GMT
I have been running this scenario in my head for a while.  In the
surface it seems fine, but I keep thinking that somehow it will cause
problems.

class A {
}

class B extends A {
}

class C extends A {
   B myB;
}

Class B is a A

Class C is also a A but also has a B which is in turn a A.

Is there anything wrong with having a variable in a class of a type
that inherits from the same parent that the class itself inherits from?

Thanks.
Mike Schilling - 19 Feb 2006 21:45 GMT
>I have been running this scenario in my head for a while.  In the
> surface it seems fine, but I keep thinking that somehow it will cause
[quoted text clipped - 16 lines]
> Is there anything wrong with having a variable in a class of a type
> that inherits from the same parent that the class itself inherits from?

Not at all.  Consider that A might be "java.lang.Object".
Jeffrey Schwab - 20 Feb 2006 14:26 GMT
>>I have been running this scenario in my head for a while.  In the
>>surface it seems fine, but I keep thinking that somehow it will cause
[quoted text clipped - 18 lines]
>
> Not at all.  Consider that A might be "java.lang.Object".

Nicely put!
jstorta - 20 Feb 2006 20:42 GMT
It makes perfect sense when you put it that way.

Thanks.


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.