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

Thread: Just a simple one for a newbie!!

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Just a simple one for a newbie!!

    I want to call a value from another class but not sure how:

    class Angle{
    double angleStart;

    public Angle(){
    angleStart = 0;

    Where the value is 0 i want to call in a value entered earlier in the program i gues u use a get command?


  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Just a simple one for a newbie!!

    Quote Originally Posted by scones73 View Post
    I want to call a value from another class but not sure how:

    class Angle{
    double angleStart;

    public Angle(){
    angleStart = 0;

    Where the value is 0 i want to call in a value entered earlier in the program i gues u use a get command?

    Hi,
    You just need to create a class with main method and use this code

    Angle angle=new Angle();
    System.out.println(angle.angleStart);

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Just a simple one for a newbie!!

    Thanks for the reply but its not called angle earlier in the programme - i want to call in the value from something else and store it as the new value for angle - is that possible??

  4. #4
    Junior Member
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Just a simple one for a newbie!!

    Rule is "if u want to call any member of any class then u have to create an object of that class then u can call that variable or method".

    Sorry I am not able to understand your problem properly. can u be more specific for your requirement.

  5. #5
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Just a simple one for a newbie!!

    i used a value in a variable earlier in the programme called tempPosition and the outputted it - i now want to reuse the original value to do another calculation...sorry im not very good at explaining

  6. #6
    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: Just a simple one for a newbie!!

    i now want to reuse the original value
    Where did you save the original value? If you assign a new value to a variable, the original value is gone.
    Or if the variable is defined locally to a method, when the method exits all its local variables go away.

  7. #7
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Just a simple one for a newbie!!

    You also know that sometimes you can use methods that are static without having to instantiate an object right?

  8. #8
    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: Just a simple one for a newbie!!

    Quote Originally Posted by elisha.java View Post
    You also know that sometimes you can use methods that are static without having to instantiate an object right?
    A bad approach without having the real need and use of static to use static.

    Also, scones73: Why don't you read about getters and setters (accessors and mutators) to accomplish your job?

Similar Threads

  1. Newbie: general question on trying to get a simple Pokemon game to work
    By willmer in forum Object Oriented Programming
    Replies: 7
    Last Post: July 13th, 2011, 07:33 AM
  2. Help!, newbie, interested in Java, Very simple code, completely stuck!
    By munkybunky in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 30th, 2011, 07:25 AM
  3. Replies: 13
    Last Post: October 13th, 2010, 11:20 AM
  4. java newbie..simple mail server implementation
    By saurabh4dudes in forum Java Networking
    Replies: 0
    Last Post: March 12th, 2010, 08:53 AM
  5. Newbie needs help in simple servlet program
    By visitor1078 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 19th, 2009, 01:46 PM