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

Thread: one variable in a third class is being reported as holding different values when references from objects in two different classes! please help!

  1. #1
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default one variable in a third class is being reported as holding different values when references from objects in two different classes! please help!

    D


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: one variable in a third class is being reported as holding different values when references from objects in two different classes! please help!

    How many FuelGuage class objects does the code create?
    Should there only be one that all other classes share?
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    javaiscool (March 20th, 2013)

  4. #3
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default Re: one variable in a third class is being reported as holding different values when references from objects in two different classes! please help!

    D

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: one variable in a third class is being reported as holding different values when references from objects in two different classes! please help!

    Most cars have only one per fuel tank.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #5
    Member Chris.Brown.SPE's Avatar
    Join Date
    May 2008
    Location
    Fort Wayne, Indiana
    Posts
    190
    Thanks
    1
    Thanked 31 Times in 31 Posts

    Default Re: one variable in a third class is being reported as holding different values when references from objects in two different classes! please help!

    This would be a great example of where to use the Singleton Design Pattern. If you know that your program is only ever going to need one instance of an object that's what you should do. Then any class can grab the instance from the class itself instead of having to pass it from one to another.
    Writing code is your job, helping you fix and understand it is mine.

    <-- Be sure to thank and REP (Star icon) those who have helped you. They appreciate it!

Similar Threads

  1. Getting primitive variable values from another class
    By Giacomo in forum What's Wrong With My Code?
    Replies: 9
    Last Post: January 27th, 2013, 01:09 PM
  2. Using values in different classes
    By The_Mexican in forum Java Theory & Questions
    Replies: 2
    Last Post: November 19th, 2010, 08:08 PM
  3. Need help passing values through classes
    By Jared in forum Java Theory & Questions
    Replies: 2
    Last Post: October 6th, 2010, 08:42 AM
  4. How to share variable values amongst different classes?
    By igniteflow in forum Object Oriented Programming
    Replies: 8
    Last Post: August 20th, 2009, 08:53 AM
  5. Replies: 6
    Last Post: May 15th, 2009, 05:06 PM