P
pqh10182008
Unregistered / Unconfirmed
GUEST, unregistred user!
请教一个问题,以下程序的输出我觉得两行都为subclass.
为什么第一行为baseclass呢?方法不是动态绑定的吗?
import java.util.*;
class Instrument {
public void play() {System.out.println("
baseclass"}
static void tune(Instrument i) {
i.paly();
}
}
public class Wind extends Instrument {
public void play() {System.out.println("
subclass"}
public static void main(String[] args) {
Wind flute = new Wind();
Instrument.tune(flute);
// Upcasting
flute.play();
}
}}
为什么第一行为baseclass呢?方法不是动态绑定的吗?
import java.util.*;
class Instrument {
public void play() {System.out.println("
baseclass"}
static void tune(Instrument i) {
i.paly();
}
}
public class Wind extends Instrument {
public void play() {System.out.println("
subclass"}
public static void main(String[] args) {
Wind flute = new Wind();
Instrument.tune(flute);
// Upcasting
flute.play();
}
}}