Static Keyword Cheatsheet

 Static Cheat sheet for Quick Revision

  • Static is a Non Access Modifier.
  • Static modifier can be applied to Variable / Method / Block / Inner Class.
  • Static members belong to class only not any instance.
  • Static method can not access instance variable.
  • Static methods can not be overriden. As they are class specific and doesn’t belong to any Instance.
  • Static methods can be redefined.
  • Static variable can not be directly accessed by Non Static Methods.
  • If a class contain any static block then that block will get executed only when class get loaded in JVM. Creating multiple instances doesn’t mean that Static block will get executed multiple time. Only Constructor will get executed multiple time.
  • If Class.forName(“class_name“) is called then static block of the class will get executed.

Leave A Comment

Your email address will not be published. Required fields are marked *