By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

help: composition & aggregation etc static non-static error message

P: n/a
to learn java I'm working on an eco-system simulation, the source's at:
http://www.geocities.com/cjavacjava/src/

class XYZcoordinates has three fields: int x,y,z

class Cat inherits from abstract class LifeForm

each cat needs one and only one XYZcoordinates object

I think I know what I want, but keep getting errors about
static/non-static references to static/non-static variables.

please do look at the code :)
ja***@mail.com
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ja***@mail.com (javac) wrote in news:64d923a9.0403291144.418bc7f5
@posting.google.com:
http://www.geocities.co


Your method "main" within "Cat" does not instantiate any objects of class
"Cat". Thus, how does the compiler know which "Cat" object your are talking
about (since you don't have any)?

You are missing:

Cat mycat = new Cat();

and also:

System.out.println(mycat.xyz.getX()) ;

Note that you have to have a "Cat" to do something with its "XYZcoordinates"
object.

Once you get the above working:

Shouldn't your "LifeForm" class have a getter for xyz ? Maybe setters too?

Good Luck!

--
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.