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 3 of 3

Thread: Gathering variables?

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Gathering variables?

    I have a question on general Java.

    Say I have a class:


    Mod1:

    package com.deathman12e3

    public class Mod1
    {

    public static Item hi = new Item(1000);

    }


    and


    Mod2:

    package com.deathman12e3

    public class Mod2
    {

    public static Item hello;

    }


    How would I set "hello" to "hi" with out doing this?

    public static Item hello = Mod1.hi;


  2. #2
    Member
    Join Date
    Jul 2013
    Location
    Franklin, TN
    Posts
    47
    Thanks
    3
    Thanked 4 Times in 4 Posts

    Default Re: Gathering variables?

    Umm if you are trying to refer to a variable unstaticly you can use methods
    IE in Mod1.java have..
    public Item getItem(){
        return hi;
    }

    and then reference the public void from the new object in your Mod2.java
    public Item hello = Mod1.getItem();

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Gathering variables?

    Homework question?

Similar Threads

  1. Help Passing Variables
    By jo15765 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: May 7th, 2012, 08:22 PM
  2. Differences between local variables and instance variables
    By rob17 in forum Java Theory & Questions
    Replies: 2
    Last Post: March 6th, 2012, 08:34 PM
  3. Instance Variables and local variables difference
    By dcwang3 in forum Java Theory & Questions
    Replies: 3
    Last Post: October 31st, 2011, 06:33 AM
  4. Scope of Variables
    By PineAppleKing in forum Java Theory & Questions
    Replies: 5
    Last Post: June 11th, 2011, 10:22 AM
  5. Data Gathering Java Program
    By BLACKWOLFXIII in forum Java Networking
    Replies: 2
    Last Post: May 17th, 2011, 10:33 AM

Tags for this Thread