rafa Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however, your name is not in keeping with our naming policy here at the ranch. Please re-register under an appropriate name as shown in the policy. Thanks again and we hope to see you around the ranch!!
What error are you getting in your code? The interface has no method definition for the implementing class to inherit - in fact the implementation it inherits from the class it is extending should satisfy the interface.
Are these methods exactly the same? You can to what You want only if methods are exactly the same (same arguments and return types) or if they have different argument types or arguments count. [ February 13, 2002: Message edited by: Maciej Kolodziej ]
hi, I guess since interface has no implementation. At run time, when you can super, there is only one implemented method, which is the class you extends. So, there is no confusion. Am I right? Thanks Kawaii
It occurs to me that you might have a class and an interface which have a method with the same name and signature, but different return types. In this case it would [i]not[/] be possible to extend the class and implement the interface in the same class. There might be similar problems if the access modifier or throws clauses are different, but these can be circumvented as long as the new method (a) is declared public, and (b) does not itself declare any exceptions thrown which are not declared in both other versions of the method. You can always override a method with one which is more public and throws fewer exceptions - but you can't change the return type.
"I'm not back." - Bill Harding, Twister
Joined: Jan 26, 2001
I was thinking what would happen if super.method() is called. It proves to be fine since interface does not have a implementation for the method. But it is really confusing to me when it comes to this kind of inheritance hierarchy.
Method implementations only happen in classes. All an interface does is define a set of methods that classes can declare they implement. If class A implements interface I, that just means class A needs to implement the methods defined in I. If A extends another class, that superclass doesn't have to implement I, so it's quite possible methods in I won't be present in the superclass. In this case, calling super.method() has the same exact effect as when you try to call a method that doesn't exist, either in the superclass or just in a regular class.