aspose file tools*
The moose likes Beginning Java and the fly likes inheritance from more that once source.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inheritance from more that once source...." Watch "inheritance from more that once source...." New topic
Author

inheritance from more that once source....

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
ok i have my main file... "fighter.java"

in that file i have the line of code as following



ok, what i want to do is extend from an abstract file i made my self...
but it won't let me...

so, basiclly, how do i inherit from more that one file, or can I, and if
I can't, is there a way around it?

thanks,
Monk


You down with OOP? Yeah you know me!
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
No. You can't extend more than one class at a time. You can implement as many interfaces as you want.
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
sweet A, but interfaces can only have abstract methods.....

what im trying to do is clean up my code...

by putting my draw methods in a different class and calling them

but i need the protected variables so i can modify as needed

any solution, I would LOVE it!

monk
Alana Sparx
Ranch Hand

Joined: Feb 14, 2006
Posts: 121
Well, can you
a)not provide your protected variables with public get/set methods and declare this in a seperate class?
b)if you absolutely must refer to the variables, declare them in another class in the same package? You will still be able to refer to them through an instance of this class.
c)extend from your parent as you wished, and get that parent to extend JPanel?

Just some thoughts.....
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
ok, maybe im just retarded,

but i have a main file that draws and stuff....and has the listeners,

the other file i want to make only would have

methods that are in my main file right now, the only reason i want

to make a separate one, is to clean up my main file a lil.

cause i know you can use public methods in any class that is public...

but the thing is.... i have certain X coordinate variables that i

increase and decreased as need in the game... so

the methods would be

public void drawGuy()
{//mycode}

and

public void drawFireball()
{//mycode}

if the file is public....can i still modify the variables as protected
and use them, or does it have to be abstract to do so?

LOL thx,
Monk
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
ok screw beating around the bush,

want i really want to know is ok,

i have the method drawFireball() right?

well i want to call it in my KeyListener...

but when i do it won't recognize 'g'...

how do i call it?

wat is a solution to get around it?...

if i can get around it in the same class...then i can
implement the same ideas in the second one...

thanks again,
Monk
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
One way around it would be to create a JPanel whose paint method does what you want drawFireBall to do.
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
ok, but if i make my own JPanel and extend from it, i wont have all the

characteristics of the actual JPanel class , just my instance of it..

monk.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Originally posted by Monk Fox:
ok, but if i make my own JPanel and extend from it, i wont have all the

characteristics of the actual JPanel class , just my instance of it..

monk.


If you make an extension of JPanel, you will have all of the characteristics of a JPanel as well as what you add to it. You can override the paint method in your extension and have it draw the fireball.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inheritance from more that once source....