就是一个很简单的接口多继承的例子- interface Playable {
- void play();
- }
- interface Bounceable {
- void play();
- }
- interface Rollable extends Playable, Bounceable {
- Ball ball = new Ball("PingPang");
- }
- class Ball implements Rollable {
- private String name;
- public String getName() {
- return name;
- }
- public Ball(String name) {
- this.name = name;
- }
- public void play() {
- ball = new Ball("Football");//这里报错,写Ball ball=new Ball("Football")也出问题,什么错误
- System.out.println(ball.getName());
- }
- }
复制代码 |
|