File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes interface question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "interface question" Watch "interface question" New topic
Author

interface question

k Oyedeji
Ranch Hand

Joined: Jul 07, 2002
Posts: 96
Hi
If i have an interface which defines a method which subclasses must implement can the method be overloaded in the subclass. For example an interface defines a method :
public String getPersonalDetails( String name ){};
in a class that implements this interface can i also have a method such as :
public String getPersonalDetails(string firstname, String Surname){
....
}
in the class implementing the interface?
Thanks
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Sure - give it a try; it works.


"I'm not back." - Bill Harding, Twister
Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
does it work?
you have tried it,Jim Yingst?
I feel a method in the class which implements a interface can just OVERRIDING the method in the implemented interface instead of OVERLOADING it.
Am I right?I got confused


a beginner in java
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
does it work?
As I said: give it a try; it works. Of course you have to correct a few errors in the code given, like replacing "string" with "String", and an interface declaration can't have a method body (so delete the "{}"). Note also that the original poster asked "can i also have a method such as..." - the also implies he/she wants to actually implement the interface by overriding the required method, and also create an overloaded method. Which is perfectly legal.
Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
Clear illustration,Jim Yingst.
I made a misunderstanding!
k Oyedeji
Ranch Hand

Joined: Jul 07, 2002
Posts: 96
Thanks for the reply you were right, i do want to implement the interface method as well as another but out of curiosity, would it also be possible to implement an interface and provide an implementation for a method which had a different signature?
THanks
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
No - in order to implement a method from an interface, you must match the signature. You could provide another method which overloads this if you like, which has a different signature. But that has nothing to do with the interface, which requires a specific signature.
k Oyedeji
Ranch Hand

Joined: Jul 07, 2002
Posts: 96
Jim
THanks, thats just the answer i was looking for
Kola
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: interface question