Online Software Educational Training - IT Tutorials - Online Education Training for Computer Software


Home

JAVA PROGRAMMING

Static and Final

The static keyword

Normally a class member must be accesses only in conjunction with an object of its class. However it is possible to create a member that can be used by itself, without reference to a specific instance. To create such a member, precede its declaration by static keyword. 

Method declared as static have several restrictions:

  • They can only call other static methods
  • They must only access static data
  • They cannot refer to this or super in anyway.

The final keyword

The final keyword has slightly different meanings depending on the context, but in general it says "This cannot be changed." You might want to prevent changes for two reasons: design or efficiency. Because these two reasons are quite different, it's possible to misuse the final keyword.

 


Previous

Next