aspose file tools
The moose likes Beginning Java and the fly likes what is the difference between final, static, and final static. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "what is the difference between final, static, and final static. " Watch "what is the difference between final, static, and final static. " New topic
Author

what is the difference between final, static, and final static.

kasthala kasturi
Greenhorn

Joined: Dec 20, 2006
Posts: 3
Hello All,
can anyone answer to this question.I know what static member does,and final member does.But please anyone tell me what is the use of declaring final static to a member.Thank you in advance.
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 434

IMHO

final - Makes the member value be constant (cannot be changed).
static - All instances of a class share the member.

I'd say,

final + static - All instances of the class share the member and its value cannot be changed.

Hope this helps and answers your question?

-Raj.
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
If you refer to static member variables, then the final keywork is used to create constants.

The variable belongs the class and cannot be altered, therefore it is considered a constant.

If you refer to static member methods, the final keyworkd avoid that other classes in the hierachy shadow the original method declaration.

You know that static members are not inherited, therefore static methods are not inherited either. But a subclass could shadow a static method declaration in the parent class, unless the static method is declared final.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the difference between final, static, and final static.
 
Similar Threads
why inner class can't have static modifiers???
Nested enum in enum.
Spot the difference
Need clarification on serialVersionUID variable in java class.
static vars in inner classes