本文共 1018 字,大约阅读时间需要 3 分钟。
展开全部
interface Shape{ //例如计算长方体的体积与面积
public void area();
public void cylin();
}
class Cylinder implements Shape{
private double lo;
private double weigth;
private double higth;
public Cylinder(double lo,double weigth,double higth){
this.setLong(lo);
this.setWeigth(weigth);
this.setHigth(higth);
}
public void setLong(double l){ //set方法
this.lo = l;
}
public void setWeigth(double w){
this.weigth= w;
}
public void setHigth(double h){
this.higth= h;
}
public double getLong(){ //get方法
return this.lo;
}
public double getWeigth(){
return this.weigth;
}
public double getHigth(){
return this.higth;
}
public void area(){
double area = lo*weigth*4 + weigth*higth*2;
System.out.println(area);
}
public void cylin(){
double cylin = lo*weigth*higth;
System.out.println(cylin);
}
}
public class Demo04{
public static void main(String args[]){
Cylinder cl = new Cylinder(5.0,5.0,5.0);
cl.cylin();
cl.area();
}
}//如有单词啥的品写错32313133353236313431303231363533e58685e5aeb931333337396164了望勿见怪
还望了调用方法了呢,自己加上去吧。呵呵
sorry刚刚犯低级错误了,现在更正了
转载地址:https://blog.csdn.net/weixin_32820131/article/details/114474550 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!