Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Rep Power

    Default global variables

    I have a problem on how to define a global variable. Does anyone know how I can make from P1 a global variable so that other classes can use it too?

    Java Code:
    public class X
    public String P1;
    public String P2;
        public PlayerID(String player1,String player2)
            P1 = player1;
            P2 = player2;

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    Consider creating a Player class that holds a String name field and have "X" accept two Player objects. How to make it visible to critical parts of the program will depend on how the Program structure. My guess is that you'll probably make it a class variable of some "Game" class, and then pass it as a parameter to any other objects used by Game.

Similar Threads

  1. global declaration in java
    By gpveena20 in forum New To Java
    Replies: 13
    Last Post: 02-12-2009, 11:25 PM
  2. Would you like to publish your game global?
    By tridens in forum Reviews / Advertising
    Replies: 0
    Last Post: 08-18-2008, 10:42 AM
  3. Global constants
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-17-2008, 10:06 AM
  4. Declaring global variables
    By eva in forum New To Java
    Replies: 3
    Last Post: 12-23-2007, 01:11 AM
  5. save global data in servlets
    By Marty in forum Java Servlet
    Replies: 1
    Last Post: 05-31-2007, 07:38 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