变量调用分析——这个ball到底是那个ball?
public class Ball implements Rollable{
public static void main(String[] args) {
Ball ball = new Ball("lanqiu");
System.out.println(ball.getName());//这里程序为何不报错?如何区分新实例ball和接口中的ball
ball.play();
Rollable.ball.play();
}
private String name;
public String getName(){
return name;
}
public Ball(String name){
this.name = name;
}
@Override
public void play() {
// ball = new Ball("Football");
System.out.println(ball.getName());
}
}
interface Playable{
void play();
}
interface Bounceable{
void play();
}
interface Rollable extends Playable,Bounceable{
Ball ball = new Ball("PingPang");
}
posted on 2022-09-27 21:09 dequantianhe 阅读(16) 评论(0) 编辑 收藏 举报