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 / March 2004

Tip: Looking for answers? Try searching our database.

composition & aggregation etc  static non-static error message

Thread view: 
javac - 29 Mar 2004 20:45 GMT
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 :)

javac@mail.com
GV - 31 Mar 2004 09:41 GMT
> to learn java I'm working on an eco-system simulation, the source's at:
> http://www.geocities.com/cjavacjava/src/
[quoted text clipped - 11 lines]
>
> javac@mail.com

You need a 'cat' object first.

package staticFactoryEcoSystem;

public class Cat extends LifeForm {

   public Cat() {
       System.out.println("Cat default constructor..");
   }//Cat

   public static void main(String[] args) {
       System.out.println("Cat main..");
       //xyz.getX();
       //this generates an error:

       //create a cat object
       Cat myCat = new Cat();

       //get that cat's xyz reference (it's public as declared in LifeForm)
       int x = myCat.xyz.getX();
       System.out.println("The x coordinate = " + x);
   }//main

}//Cat


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.