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 / December 2007

Tip: Looking for answers? Try searching our database.

Inheritance and stuff

Thread view: 
mnml - 08 Dec 2007 16:38 GMT
Hi,
I have two class and I would like to use one of the Variable from the
child class in one of the parent class's function,
Is there a way to do that, should I use an Interface?

Regards.
Andrew Thompson - 08 Dec 2007 16:59 GMT
...
>I have two class and I would like to use one of the Variable from the
>child class in one of the parent class's function,
>Is there a way to do that, should I use an Interface?

Can you describe an actual example* where that makes
any sense?

* Concrete, as opposed to abstract.

Signature

Andrew Thompson
http://www.physci.org/

mnml - 08 Dec 2007 17:42 GMT
> ..
>
[quoted text clipped - 11 lines]
>
> Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-general/200712/1

ok then I have a Parent class : Elements
and i have a child class : Player

The pos_x and the pos_y of my Player are part of defined in the Player
class ( pos_x = 20; pos_y = 20;// as a starting position )

In my Elements class I have a Function using that value but here is my
problem: if I don't define int pos_x in the Elements class it return
me an error because it can't find the Variable. If I define it it
doesn't care about the value set in my Player class when i use the
actual function.
Andrew Thompson - 08 Dec 2007 17:58 GMT
...
>ok then I have a Parent class : Elements

Elements?  What does that mean?

>and i have a child class : Player

I could understand Player being sub-classed to
PokerPlayer and FootBallPlayer, or perhaps
AudioPlayer and VideoPlayer, but what is the
relationship between an 'Element' and a Player?

( If it makes sense to have the Element access the
attributes within a method, perhaps they should be
attributes of Element, rather than Player.  And as
an aside, how would the Player class in my example,
decide whether to use the defaultPlayTime of, for
example, AudioPlayer or VideoPlayer? )

BTW
- The word 'I' should always be upper case.
- 'OK' is also upper case.
- A ..
 - Function in Java is more commonly referred to as a method.
 - Variable -> attribute

Signature

Andrew Thompson
http://www.physci.org/



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



©2008 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.