在idea中测试没有问题,为什么不能通过?
package zh.codegym.task.task14.task1407;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
乐手和舞者
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Person person = null;
String key;
while (!(key = reader.readLine()).equals("exit")) {
if ("乐者".equals(key)) {
person = new Player();
} else if ("舞者".equals(key)) {
person = new Dancer();
}
// haveFun(person);
}
}
public static void haveFun(Person person) {
if(person instanceof Player){
new Player().play();
}
if(person instanceof Dancer){
new Dancer().dance();
}
}
interface Person {
}
static class Player implements Person {
public void play() {
System.out.println("演奏");
}
}
static class Dancer implements Person {
public void dance() {
System.out.println("跳舞");
}
}
}