Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

difference bet static and final  RSS feed

 
bharath pawan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between below two statements?
final int i=5;
static final int i =5;
 
Sridhar Padala
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

Both are contants and never be changed, but only variable with only final modifer means its one constant per instance whereas final static menas its per class. final variable can be intialized to 10,20 or 30 in their respecive constructors as each object has its own copy of final variable, but static final means we can assign only one value, as it is only one per class.

All The Best
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem is the meaning of the static keyword.
A clear explanation with an example can be found here.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!