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

static method  RSS feed

 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
why can't a static method can't access non static methods or var's.
Take me to deep.

-----
Raj
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A static method belongs to the class. In the context of execution of a static method it is possible that not even one instance of the class exists yet. Therefore, if you try to invoke an instance method from within an static method, the class has no way to know what particular instance of the class you are referring to.

That is why a instance method is allowed to execute a static method, but the contrary is not possible. If you want to invoke a instance method from whithin the static method you must create the instance first.



All you need to understand is that static method acts over the class, and not over any particular instance of the class. While an instance method acts over a particular instance.
[ December 20, 2006: Message edited by: Edwin Dalorzo ]
 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Edwin


" End Less Journey ---> Learning "

---
Raj
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!