Re: Implementing two interface methods with same signature



On 6 Oct 2005 23:10:08 -0700, "jjoensuu" <j_joensuu@xxxxxxxxx> wrote:

>interface VacationSpots {
> //return true if location is a resort
> boolean resort();
>}
>
>interface SortRooms {
> //return true once rooms are sorted
> boolean resort();
>}
>
>public class Resort implements VacationSpots, SortRooms {
> //other code
> boolean isResort;
> //other code (constructor etc)
> public boolean resort(){
> return isResort;
> }
> //other code
>}
>
>QUESTION: In this sort of a case, which "resort" method is actually
>implemented?

Does it really matter? All an interface does is define a set of
methods that any implementing classes must implement. Its a contract
with an implementing class,.

Using your example, the both would be valid and would result in
calling the same method:

VacationSpots spot = new Resort();
spot.resort();

and

SortRooms rooms = new Resort();
rooms.resort();

So, in effect, it doesn't matter who's resort method it is.

--
now with more cowbell
.