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

static - i am a little confused about this  RSS feed

 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i declare something that is static that means it doesnt change right?Methods when i use static means that this method cant change?On the main its urge to declare the methods static?can i declare a static method and on other class?Am i right?
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ekte spiriopoulos wrote:When i declare something that is static that means it doesnt change right?Methods when i use static means that this method cant change?On the main its urge to declare the methods static?can i declare a static method and on other class?Am i right?


No. The "static" keyword doesn't do what you are describing... perhaps you are thinking of the "final" keyword? And even then, some of the stuff that you mentioned don't apply.

Henry
 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ekte spiriopoulos wrote:When i declare something that is static that means it doesnt change right?Methods when i use static means that this method cant change?On the main its urge to declare the methods static?can i declare a static method and on other class?Am i right?
what exactly does this static ?i know how to use on an exercise but i dont know why.Example : i have a class userinput and on my main i write for example static int x; and after x=UserInput.get.Integer(); .I am just curious what does this static.Another example is when i finish my main down of it i write inside the same class private static void or what is it(i mean int,double etc..),is this right?
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hmmm... Perhaps it would be a good idea to find a tutorial? Or perhaps to review the book that you are using?

While a forum is very good at getting elaborations on specific details, especially great when the distinction are subtle -- your level of confusion seems at a very high level (ie. confusing final and static). It may be much more efficient to use a tutorial instead.

Henry
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At your stage, regard static as a mistake unless you find a good reason to use it.
Something static belongs to the class rather than the object. The word static has a convoluted history and it now means something different from what it means in older languages like C.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!