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: class constants instance constants..... etc

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default class constants instance constants..... etc

    i need some brief explanation about these types of data values.... just a little bit of understandable explanation about these...

    for example

    private static final int FIRST_NUMBER = 1; //this is a class constant

    but the book that i've red says that if THIS constant variable declared as..
    like this..

    private final int FIRST_NUMBER = 1; //then this is an instance constant

    every instances of the class will have the same value


    i dont get this point...

    just a little bit of understandalbe explanation.


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: class constants instance constants..... etc

    These two lines have one difference and that is the static keyword.

    A static variable exists only once per class, if the variable was not final you could change it in one reference of the class and it would change in the other class as well.

    See What does the 'static' keyword do in Java? - Stack Overflow

    // Json