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

Thread: Saving a var in private class member

  1. #1
    Junior Member
    Join Date
    Dec 2022
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Saving a var in private class member

    Hi, sorry for the simple question but I am stuck.

    I am upgrading from one API to a new API.

    In the old app the var I was interested in was

    int totalQuantity;

    I could change its value with

    parent.totalQuantity = 5;

    Now the API has changed and it is part of a class defined as:

    private Decimal m_totalQuantity = Decimal.INVALID;

    It has a setter method

    public Decimal totalQuantity() { return m_totalQuantity; }

    I cannot figure out how to set this var and have tried:
    order.totalQuantity(Decimal(1));/
    order.totalQuantity(Decimal.valueOf(5));

    How do I change the value of the private totalQuantity var????

    Thank you for your help.

    Miamimike

  2. #2
    Member
    Join Date
    Jun 2022
    Posts
    41
    Thanks
    1
    Thanked 3 Times in 2 Posts

    Default Re: Saving a var in private class member

    That's not a setter, that's a getter. You can tell the difference because it takes no inputs and returns an output.
    And it's there specifically to prevent you from fiddling with the variable m_totalQuantity, which presumably is a calculated value.
    Last edited by AngleWyrm; December 11th, 2022 at 03:59 PM.

Similar Threads

  1. private final class
    By thelegendery in forum Java Theory & Questions
    Replies: 1
    Last Post: May 29th, 2013, 06:23 AM
  2. Why do we make variables of a class private?
    By Pratyush in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 1st, 2013, 02:26 AM
  3. Help setting a private static class variable
    By kyuss in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 26th, 2010, 08:09 AM
  4. final class, final <variable> or <data member>
    By chronoz13 in forum Object Oriented Programming
    Replies: 9
    Last Post: September 20th, 2009, 08:19 AM