import java.util.Random;
public class Test {
public static void main(String[] args) {
System.out.println("---欢迎--姓名--学号--来到演播厅---");
Instument ins = getInstrument();
if(ins instanceof Erhu) {
((Erhu) ins).playing();
}else {
ins.play();
}
}
static Instument getInstrument() {
Random rnd = new Random();
int n = rnd.nextInt(3);
Instument ins=null;
switch(n) {
case 0:
ins = new Instument();
break;
case 1:
ins = new Erhu();
break;
case 2:
ins = new Violin();
break;
}
return ins;
}
}
class Instument{
void play() {
System.out.println("乐器演奏中");
}
}
class Erhu extends Instument{
void play() {
System.out.println("二胡演奏中...");
}
void playing() {
System.out.println("二泉映月...");
}
}
class Violin extends Instument{
void play() {
System.out.println("小提琴演奏中...");
}
}