Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How do I access an Object from anywhere?

  1. #1

    Default How do I access an Object from anywhere?

    I want to be able to just type a class name and then the object to access it.
    Basically kinda like this:

    GL10 gl = ObjectHandeler.gl;
    [Please note that ObjectHandeler is a class]

    Is there any way to go about this, and how would I do it? I need a GL10 object that I can access absolutely anywhere.
    Thanks in advance. (In the past I just passed around the object using methods, but it isnt very efficient and flexible...)


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How do I access an Object from anywhere?

    Is ObjectHandeler the name of a class (by convention it is because of its spelling)?
    If it is the name of a class and gl is a public static member of that class then your code should work.
    An example would be the out variable in the System class. You can access it anywhere.

    Making a variable static means there is only one of them and it has the last value assigned to it.

  3. #3

    Default Re: How do I access an Object from anywhere?

    If i make it static, can i still modify it? (Like setting it to null, etc...)

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: How do I access an Object from anywhere?

    Quote Originally Posted by nivangerow View Post
    If i make it static, can i still modify it? (Like setting it to null, etc...)
    Did you try doing this? Don't ask such questions, how to do this, what will happen, will it work. Why don't you try it and have an experience.

Similar Threads

  1. Calling from one javabean object to other javabean object in a single class
    By kichkich in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 24th, 2011, 07:20 AM
  2. Reading from ResultSet to Object and from object Object Array
    By anmaston in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 7th, 2011, 06:11 AM
  3. Database access..
    By _lithium_ in forum JDBC & Databases
    Replies: 7
    Last Post: March 2nd, 2011, 10:32 PM
  4. 2D Object makes my object smaller, Why?
    By MassiveResponse in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 15th, 2010, 02:33 PM
  5. Default Access (package access) confusion
    By gauravrajbehl in forum Java Theory & Questions
    Replies: 1
    Last Post: November 18th, 2009, 04:11 AM

Tags for this Thread