向上转型

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-----");
	}
}


 
 

你可能感兴趣的:(Java编程思想)