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

static&protected  RSS feed

 
muralik krishnam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A static variable is available to the entire class.
A protected variable is available to the classes in the same package and sub classes in other packages.

what happenes if the variable is both static and protected?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by muralik krishnam:
A static variable is available to the entire class.


"static" has nothing to do with access control.

A static field or method is used without reference to an instance of the class. A non-static field or method can only be used through a reference to an instance of the class.

"protected" is an access modifier.

So "static" and "protected" are totally different and asking the difference between them is like asking the difference between "fast" and "blue".
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!