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: Static vs Instance

  1. #1
    Member
    Join Date
    Oct 2021
    Posts
    63
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Static vs Instance

    I have two statements that I would like examples/deep explanations on.

    Here there are :

    (1)
    "Always reference static variables and methods from a class name (rather
    then a reference variable) to improve readability and avoid errors."

    (2)
    "Do not pass a parameter from a constructor to initialize a static data
    field. It is better to use a setter method to change the static data field."
    Last edited by siid14; August 31st, 2022 at 08:28 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Static vs Instance

    I agree with (1)
    I don't know about (2)
    What author recommends those?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Oct 2021
    Posts
    63
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: Static vs Instance

    Y. DANIEL LIANG

Similar Threads

  1. Replies: 1
    Last Post: June 5th, 2017, 08:01 PM
  2. Replies: 6
    Last Post: May 3rd, 2013, 04:25 PM
  3. "Static method cannot hide instance method from implemented Interface"
    By Gthoma2 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 21st, 2011, 03:03 AM
  4. Replies: 10
    Last Post: September 6th, 2010, 04:48 PM
  5. [SOLVED] static variable in an instance method?
    By chronoz13 in forum Java Theory & Questions
    Replies: 2
    Last Post: January 30th, 2010, 03:24 AM

Tags for this Thread