| RedefTry.java - Et kunstigt program som illustrerer redefinition af variable og metoder, og dynamisk binding af metoder. | Lecture 7 - slide 35 : 41 Program 1 |
class A {
protected int v = 5;
protected void m(int p){
v = p;
}
}
class B extends A{
protected int v = 6;
protected void m(int p){
v = p;
super.m(p-3);
}
public String toString(){
return("B: " + "this.v = " + this.v + ", super.v = " + super.v );
}
}
class RedefTry {
public static void main (String[] args){
A aB = new B();
aB.m(7);
System.out.println(aB);
}
}
|