Ball类的继承

来源:互联网 发布:金智软件 编辑:程序博客网 时间:2024/06/05 21:00
package test;
class Ball{
private double r;
void setR(double x){
r=x;
}
double getR(){
return r;
}
}
class Billiards extends Ball{
private String color;
void setCol(double x,String clo){
r=x;
color=clo;
}
void show(){
System.out.println("该台球的半径为"+r+",该台球的颜色为"+color);
}
}
public class BallTest {


public static void main(String[] args) {
// TODO Auto-generated method stub
    Billiards b=new Billiards();
    b.setR(2);
    b.setCol("绿色");
    b.show();
}


}
原创粉丝点击