Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface

 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got a question in whizlabs mock test that can interface have static methods? i said no...it cant....but why?

is it because if we had static method in interface it would be empty....and static methods cant be inherited

are there are any other reasons too?



 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reason is the purpose why Interface has been designed.
Interface can just say what to do not how to do.
So it can only declare any method (what to do), cannot give body(how to do) to them.
There is no declaration for static methods, as static methods are class methods, not instance methods.
 
J.Augusto Gomes
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

only to member interfaces !

Oss !
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every method declaration in the body of an interface is implicitly abstract and static methods cannot be abstract.
@J.Augusto: welcome to Java Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic