编写一个java_编写一个java程序,
发布日期:2021-06-24 12:43:29 浏览次数:2 分类:技术文章

本文共 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:ignite和mysql对比_Ignite vs. MySQL vs. SAP HANA Comparison
下一篇:weixin java tools_weixin-java-tools(微信开发工具包)

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月21日 12时43分10秒