• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interfaces Cannot have static methods??  RSS feed

 
Sam Drake
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why cannot interfaces have static methods, if implementation is done only in the classes that implement those interfaces?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static methods don't participate in polymorphism - a subclass or an implementing class cannot override the implementation of something static in the parent or interface. Since the interface cannot provide a method implementation, what would it mean to declare a static method in an interface?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samurai Drake,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
Sam Drake
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Dirk, I got the point. Beginner's blues!!!
I'll change the display name too!!
 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dirk Schreckmann:
static methods don't participate in polymorphism - a subclass or an implementing class cannot override the implementation of something static in the parent or interface. Since the interface cannot provide a method implementation, what would it mean to declare a static method in an interface?

The interface is abstract, not providing an implementation, if there was a static method then the interface could never get instantiated. Am i close?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!