level 1
千里朱音ლ
楼主
题目是:创建第二个 Rectangle 对象,将其分配给一个新的变量 rect2 并设置 width 为 10 , height 为 20 并打印两个字段。
我用了如下代码
public class Main
{
public static void main(String[] args)
{
Rectangle rect = new Rectangle();
rect.width = 100;
System.out.println(rect.width);
rect.height = 200;
System.out.println(rect.height);
}{Rectangle rect2 =new Rectangle();
rect2.width = 10;
System.out.println(rect2.width);
rect2.height = 20;
System.out.println(rect2.height);}}
class Rectangle
{
int width;
int height;
}
但不知为什么只打印出来100和200 后面的rect2没打印出来,大神帮忙看看哪里错了
2016年09月16日 02点09分
1
我用了如下代码
public class Main
{
public static void main(String[] args)
{
Rectangle rect = new Rectangle();
rect.width = 100;
System.out.println(rect.width);
rect.height = 200;
System.out.println(rect.height);
}{Rectangle rect2 =new Rectangle();
rect2.width = 10;
System.out.println(rect2.width);
rect2.height = 20;
System.out.println(rect2.height);}}
class Rectangle
{
int width;
int height;
}
但不知为什么只打印出来100和200 后面的rect2没打印出来,大神帮忙看看哪里错了