• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

static vs final

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one explain static vs final modifier?

static modifier can be used with variables, methods, init block and inner classes.

final methods cannot be overridden and static methods also cannot be overridden.


Can any one explain in detail. Thanks in advance.
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
final generally means "cannot be changed"
static generally means "exists outside of an instance of an object".

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source: K&B Book
----------------------

Static:
1) Variables and Methods marked static belong to the class, rather than to any particular instance.
2) Infact, you can use a static method or variable without having any instances of that class at all.
3) A static method can't be overridden but they can be redefined ******
4) A static method cannot access a non-static variable (because there is no instance)
5) A static method cannot invoke a non-static method.

Final:
1) A Final method cannot be overridden

Hope this helps:
http://kwang.blogdns.com/tech/java-final-vs-static-variable.html
 
Rajiv Chopra
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sridhar Gudipalli wrote:Hope this helps:
http://kwang.blogdns.com/tech/java-final-vs-static-variable.html


Sridhar Thanks for link really helpful!!
 
    Bookmark Topic Watch Topic
  • New Topic