interface Playable { void play();
}
interface Bounceable { void play();
}
interface Rollable extends Playable, Bounceable { Ball ball = new Ball("PingPang"); //( Ball ball 这里定义的Ball类的对象ball在大括号外是无法使用的)
}
class Ball implements Rollable { private String name; public String getName()
{ return name; }
public Ball(String name)
{ this.name = name; }
public void play()
{ Ball ball = new Ball("Football"); //故而,这里就需要从新将Ball写在ball前边,这样就可以了
System.out.println(ball.getName()); }
}
|