Get all updates of Java4s
Follow Us: Email Newsletter

Static in Java, Static Variables, Static Methods, Static Classes

Core Java » On Oct 6, 2012 { 11 Comments } By Sivateja

Static in java  :-) very important concept in interviews.  Let us see the story behind static variables and methods and classes in java classes….

Static Variables

Observe the above class having 2 variables, 1 is instance and other is static.  If we create multiple objects of  ‘MyStatic‘ class, always instance variables will be given separate space for storage, but static variable is common to all objects of MyStatic class, no separate space will be given to each object. Any java object belongs to MyStatic class can modify that static variable,  even there is no need of creating object of a class to modify the static variables, we can modify them by its class name directly.

All java instance methods can access these static variables, and always static variables will be initialized first and then instance variables.

Static Methods

Here also same concept, we can call all static methods of a java class by its class name some thing…..


We no need to create object for MyStatic class, we can call directly just like above which is always good practice to do. In general we used these static methods to access static variables and hmm in practical we may touch these static methods in banking related applications (Account Creating Module) and even in almost all real time projects. All instance methods of a class can access these static methods, but static methods cannot access any instance types directly.

I mean all instance’ can access static, but static cannot access any instance types directly;)

Static Classes

Hope you know that we can create inner classes in java, in java only inner classes can declare as static and we used to call them as Nested classes.

You Might Also Like

  ♦ About Author ♦

Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.


11 Responses to “Static in Java, Static Variables, Static Methods, Static Classes”
  1. krish says:

    super explanation………..

  2. Anil Pandey says:

    You have removed my confusion about instance and static members.

    why wait,notify and notifyAll methods belong to object class?

    Please explain if you may?

  3. Ravi says:

    Thank U Anaya…

  4. Jitendra says:

    Nice explanation in Simple language..Thank u!!!!

  5. Anand says:

    You haven’t discussed static blocks and their restriction. static blocks can be used to add external libraries. As far as inner classes are concerned we can declare inner classes even in interfaces, surprising but do not understand why?, how can we make use of inner classes in interfaces?.

  6. Reddappa says:

    Really very good Explanation.very nice

  7. santhoshreddy says:

    How to delete static variables?

  8. sayyed RAFIKH says:

    Sir your notes is best among all please issue core java notes pointwise thank you

  9. laxman says:

    very good explanation..
    Thank you..


By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2016 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.