1定义立方体类Cube,具有属性边长和颜色,具有 方法设置颜色和计算体积,在该类的主方法中创 建一个立方体对象,将该对象的边长设置为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());
}
}
