![]() ![]() ![]() | Lecture 7 - slide 38 : 41 |
// illustration af covariant problematik i Java
class S {
private String s;
public S(){s = "S";}
public void sOp(){
System.out.println("sOp i S");
s = s + s;
}
}
class T extends S {
private String t;
public T(){t = "T";}
public void tOp(){
System.out.println("tOp i T");
t = t + t;
}
}
class A {
private String v;
public A(){v = "A";}
void meth(S p){
System.out.println("meth i A");
p.sOp();
}
}
class B extends A{
private String v;
public B(){v = "B";}
void meth(T p){
System.out.println("meth i B");
p.tOp();
}
}
class RedefTry1 {
public static void main (String[] args){
A aref;
B bref = new B();
S sref = new S();
aref = bref;
aref.meth(sref);
}
}