Problema 4
Da, un obiect poate avea mai multe tipuri.
interface A{
}
interface B{
}
interface C{
}
class X implements A,B,C{
}
class Y{
public int metoda1(A a){
return 1;
}
public int metoda2(B b){
return 2;
}
public int metoda3(C c){
return 3;
}
}
public class Main {
public static void main(String[] args) {
X exemplu=new X();
Y t=new Y();
System.out.println(t.metoda1(exemplu));
System.out.println(t.metoda2(exemplu));
System.out.println(t.metoda3(exemplu));
}
}
Aici "exemplu" este si de tipul "A" si de tipul "B" si de tipul "C".