如何将面向对象的Java基础练习改写成长尾词?
- 内容介绍
- 文章标签
- 相关推荐
本文共计217个文字,预计阅读时间需要1分钟。
定义立方体对象,具有属性边长和颜色,包含+方法设置颜色和计算体积,创建一个立方体对象,将边长设置为3,颜色设置为green,输出该立方体的体积。
ublic class Cube { float width; String color; public float getWidth() { return width; } public void setWidth(float width) { this.width = width; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } float v(){ return width*width*width; } } package gh; public class text1 { public static void main(String[] args) { Cube myCube= new Cube(); myCube.width=3; myCube.color="green"; System.out.println(myCube.color); System.out.println(myCube.v()); } }
本文共计217个文字,预计阅读时间需要1分钟。
定义立方体对象,具有属性边长和颜色,包含+方法设置颜色和计算体积,创建一个立方体对象,将边长设置为3,颜色设置为green,输出该立方体的体积。
ublic class Cube { float width; String color; public float getWidth() { return width; } public void setWidth(float width) { this.width = width; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } float v(){ return width*width*width; } } package gh; public class text1 { public static void main(String[] args) { Cube myCube= new Cube(); myCube.width=3; myCube.color="green"; System.out.println(myCube.color); System.out.println(myCube.v()); } }

