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

Interface  RSS feed

 
shashank dwivedi
Ranch Hand
Posts: 65
AngularJS Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why variables inside interface are static while methods are not?
 
sharma ishu
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because interface methods are abstract and you can't use static+abstract on a method.
Or you can say since static methods can't be overridden you must override a method in interface so you can't use static with interface methods.
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't make an object from java interface. Therefore, if the variable are not static, you can never refer them..!

You can't over-ride static methods. That's why we can't write 'static' abstract methods. Methods in an interface are implicitly abstract..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!