• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

(Design Perspective)Static method in interface

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Is there any answer why there is no static method in interface
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In an interface you cannot provide an implementation of a method and static methods are not polymorphic (they cannot be overridden), so it would make no sense to be able to have a static method in an interface: there would be no way to provide an implementation for the method.
[ July 12, 2007: Message edited by: Jesper Young ]
 
shri Sonparote
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Jesper
But we can redefine static method in implementor class.
So in that way we are giving implementation.

Regards
Shrikant
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, but static methods are not polymorphic.

Polymorphism is this: When you have a reference of an interface or superclass type, but the actual object that it refers to is of a class that implements the interface or a subclass of the superclass, and you call a method on the reference, then Java dynamically looks up the method in the actual class of the object. For example:

The context of a static method is the class, not the object that you call the method on.

It is possible in Java to call a static method via an object reference, but you should never do this, because this is confusing (in my opinion this is a flaw in the Java language; it should not have been possible to call a static method via an object reference).

If you do this, it appears as if you are calling the static method on an object, but you are really calling it on the class of the reference type.

Java regards the two sayHello() methods in the classes Super and Sub as two separate methods (that happen to have the same name). sayHello() in class Sub does not override sayHello() in class Super, as with non-static methods.
 
shri Sonparote
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Jesper

Thanks
Shrikant
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic