Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Why it is not a good practice to create static variables in Java?

Pragya Keshap answered on February 4, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • how to declare a public variable in java
  • change static variable value in java
  • java static variable
  • what is a static variable in java
  • java static variable

  • Why it is not a good practice to create static variables in Java?

    0

    Static variables are common to all the objects of a class. 

    If a new object is created, there is no need to test the value of static variable.

    Any code that uses static variable can be in any state. 

    It can be within a new object or at a class level. 

    So the scope of static variable is open ended in a Java class.

    If we want tighter control on scope, then variables should be created at the object creation level.

    Also defining static variables is not a good practice because they go against the principles of Object Oriented Programming.

    https://www.geeksforgeeks.org/g-fact-47/

    Popularity 1/10 Helpfulness 1/10 Language java
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Feb 04 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.