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: What is the Java "static" modifier for?

  1. #1
    Junior Member
    Join Date
    Apr 2023
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question What is the Java "static" modifier for?

    What is the Java "static" modifier for and how to use it correctly? And can it be used at all, what difficulties does it solve?
    Last edited by Ivan Lovushkin; April 3rd, 2023 at 08:52 AM.

  2. #2
    Junior Member
    Join Date
    Apr 2023
    Location
    India
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What is the Java "static" modifier for?

    The "static" modifier in Java is used to create class-level variables and methods that can be accessed without creating an instance of the class. When a variable or method is declared as static, it belongs to the class itself, rather than to any particular instance of the class. This means that all instances of the class share the same static variable or method.

    For example, if you have a class representing a car, you might declare a static variable https://www.scientecheasy.com/2020/0...variable.html/ to keep track of the total number of cars created, and a static method to return the total number of cars. Any instance of the car class can access the static variable and method to get or update the total number of cars.

    The static modifier can also be used to create static blocks of code that are executed when the class is loaded. This can be useful for initializing static variables or performing other setup tasks.

Similar Threads

  1. Declaring an object with the static modifier
    By Hector_M in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 17th, 2019, 11:32 AM
  2. accessors and modifier method tutorials?
    By ghostheadx in forum The Cafe
    Replies: 7
    Last Post: December 28th, 2013, 04:32 PM
  3. Private access modifier
    By pksksit in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 13th, 2013, 03:14 AM
  4. Error writing to an array with the static modifier.
    By handuel in forum Collections and Generics
    Replies: 2
    Last Post: December 25th, 2011, 11:10 AM
  5. "illegal modifier for parameter sum; only final is permitted
    By etidd in forum Java Theory & Questions
    Replies: 3
    Last Post: February 11th, 2010, 07:51 AM