Java Static Keyword Introduction

18 January 2012 By Nithya Vasudevan 628 views No Comment
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×
  • It is a non-access modifier
  • Static keyword can be applied to an instance variable or method.
    • Applying to an instance variable makes that variable as a class variable.
    • Both primitive and reference variable can be marked with static keyword
  • Static member
  • Static member belong to the class rather than to any particular instance, i.e.) it is used independently of any object of that class.
  • Static member is created using static keyword.
  • When a member is declared static, it can be accessed before any objects of its class are created, and without reference to any object.

The best example of a static member is main() method. main() should be called before any object exists , hence it is declared as static.