Results 1 to 6 of 6
  1. #1
    spatel14 is offline Member
    Join Date
    Apr 2010
    Posts
    28
    Rep Power
    0

    Default Access Public Global Variables in class

    I wrote a class Ex1 that has a public double variable. It's global, therefore it's defined outside of any method. Now, can I get access to this variable in another class, called Ex2? If so, what is the syntax to do this?

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Java Code:
    Ex1 x1 = new Ex1();
    x1.doubleMember = 2d;
    If doubleMember is an instance variable.
    Last edited by PhHein; 07-07-2010 at 07:41 PM.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    It's global
    What does that mean? I'm not familiar with the global keyword.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    Quite.
    There isn't really such a thing in Java.
    The closest is a "public static" attribute.

  5. #5
    clydedoris is offline Member
    Join Date
    Feb 2010
    Posts
    80
    Rep Power
    0

    Default

    when he says global, he refers to a class variable..
    [why are you annoyed with my sig?]

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    Except they don't say it's a class variable, because they don't say it's static. They merely say "it's defined outside of any method", and it's public. Which to me implies it's a member attribute, not a static class attribute.

Similar Threads

  1. Replies: 4
    Last Post: 10-22-2009, 05:45 PM
  2. Replies: 3
    Last Post: 03-14-2009, 07:22 AM
  3. global variables
    By blackstormattack in forum New To Java
    Replies: 1
    Last Post: 03-08-2009, 07:19 PM
  4. why we use public access modifier?
    By vichet in forum New To Java
    Replies: 1
    Last Post: 04-04-2008, 07:04 AM
  5. Declaring global variables
    By eva in forum New To Java
    Replies: 3
    Last Post: 12-23-2007, 12:11 AM

Posting Permissions

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