<pre name="code" class="java">package com.ctl.test;
class Instrument {
public void play() {
System.out.println("play");
};
static void tune(Instrument i) {
i = (UpCase) i;
i.play();
UpCase u=(UpCase)i;
u.run();
System.out.println("**************************************************");
((UpCase) i).run();
((UpCase) i).play();
}
}
public class UpCase extends Instrument {
public static void main(String[] args) {
UpCase up = new UpCase();
Instrument.tune(up);
}
void run() {
System.out.println("-----run start-----");
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(200);
System.out.println("i=" + i);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("-----run end-----");
}
}
向上转型
最新推荐文章于 2022-03-01 20:08:19 发布