i tried doing this :
interface pet {
void sleep();
}
interface robot {
void sleep();
}
public class roboGarfield implements pet , robot {
/*
* this gives error
void pet.sleep(){
}
*/
@Override
public void sleep() { System.out.println("this isn't really specific.."); }
public static void main(String[] args){
roboGarfield t = new roboGarfield();
t.sleep();
((pet)t).sleep(); // similar to C#
((robot)t).sleep();
}
}
But even though i can cast the roboGarfeild
object to its pet
or robot
type , i cant do an explicit implementation like c#.
Anything i'm doing wrong ? or is it just not supported in java ?
Edit: So , java doesn't support explicit interface implementation like C#. But for cases where they can't be avoided , Holger's delegate method seems like the way out.
Thanks for all the replies.