Results 1 to 3 of 3
  1. #1
    Join Date
    May 2010
    Posts
    24
    Rep Power
    0

    Default creating public objects

    I have a class called Parameters, like so:

    Java Code:
    public class Parameters {
    
        public enum region {
            A, B, C, D, E
        }
    
        public enum playerColour {
            RED, BLUE, GREEN, YELLOW, PURPLE, BLACK, WHITE, FREE
        }
    
        public enum Fuel_Type {
            URANIUM, COAL, OIL, HYBRID, GARBAGE, RENEWABLE
        }
    
        /*Constants*/
        public static final int COAL_TOTAL=24;
        public static final int OIL_TOTAL=24;
        public static final int URANIUM_TOTAL=12;
        public static final int GARBAGE_TOTAL=24;
        public static final int CASH_START=50;
        public static final int[] PAYOUT={10,22,33,44,54,64,73,82,90,98,105,112,118,124,129,134,138,142,145,148,150};
    
        /*Variables*/
        public Power_Stations[] stockStations;
        public int numberPlayers;
        public int numberRegions;
        public int Step;
    Then I tried to make a public instance of the class like so:

    Java Code:
            public Parameters parameters=new Parameters();
    I was rather hoping that this would mean that I could use this instance in my other classes where I'm constructing methods that use the parameters varaiables. Where am I going wrong?

  2. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    If I understand correctly, you want a global varible. Java doesn't have them, so you'll need to pass your Parameters varible to an object that needs to interact with it.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  3. #3
    Join Date
    May 2010
    Posts
    24
    Rep Power
    0

Similar Threads

  1. Creating custom objects
    By coltragon in forum New To Java
    Replies: 11
    Last Post: 12-29-2009, 11:50 PM
  2. Creating Array of Objects
    By chathurajeewaka in forum New To Java
    Replies: 4
    Last Post: 12-03-2009, 04:23 PM
  3. Replies: 1
    Last Post: 08-11-2009, 03:00 PM
  4. Replies: 5
    Last Post: 06-26-2009, 04:03 AM
  5. Creating objects question
    By sergm in forum New To Java
    Replies: 2
    Last Post: 12-27-2007, 05:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •