阅读下列程序,写出程序运行的结果:class Cube{int width;int height;int depth;Cube(int x,int y,int z){this.width=x;this.height=y;this.depth=z;}public int vol(){return width*height*depth;}}public class UseCube {public static void main(String[] args) {Cube a=new Cube(3,4,5);System.out.println("长度="+a. width);System.out.println("体积="+a.vol());}}
举一反三
- 下列程序的输出结果为 class Box{ int length,width,height; public void setInfo(int l,int w,int h){ length = l; width = w; height = h; } public int volumn(){ return length*width*height; } public int area(){ return (length*width + length*height + width*height) * 2; } public String toString(){ return "Length:" + length + " width:" + width + " height:" + height + " volumn: " + volumn() + " area:" + area(); }} public class BoxTest { public static void main(String[] args) { Box b = new Box(); b.setInfo(5,2,4); System.out.println(b.toString()); }}
- 【多选题】已知代码如下 class Rectangle { private int width, height; public void setSize(int width, int height) { this.width = width; this.height = height; } } 下面哪些代码重载 setSize 方法 (10.0分) A. protected void setSize(int width, int height) { this(width, height) } B. public void setSize(int width, float height) { this.width = width; this.height = (int)height; } C. protected void setSize(int width) { this.width = width; } D. public void setSize(int height, int width) { this.width = width; this.height = height; }
- Rectangle类中的成员变量有( )和( ) public class Rectangle{ int width; int height; public void setWidth(int x){ width = x; } public void setHeight(int y){ height = y; } public void show(){ System.out.println("宽:"+width",高:"+height); } }
- 中国大学MOOC: 已知:class Rectangle { private int width, height; public void setSize(int width, int height) { this.width = width; this.height = height; }}下面哪些代码重载 setSize 方法
- 类Rectangle中,width和height称为( )变量或( )变量。 public class Rectangle{ int width; int height; public void show(){ System.out.println("宽:"+width",高:"+height); } }