what is wrong with the following program?ublic class SomethingIsWrong {public static void main(String[] args){Rectangle myRect;myRect.width = 40;myRect.hight =50;System.out.println('myRect's area is"+myRect.area());}
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/06 18:24:05
![what is wrong with the following program?ublic class SomethingIsWrong {public static void main(String[] args){Rectangle myRect;myRect.width = 40;myRect.hight =50;System.out.println('myRect's area is](/uploads/image/z/13334808-48-8.jpg?t=what+is+wrong+with+the+following+program%3Fublic+class+SomethingIsWrong+%7Bpublic+static+void+main%28String%5B%5D+args%29%7BRectangle+myRect%3BmyRect.width+%3D+40%3BmyRect.hight+%3D50%3BSystem.out.println%28%27myRect%27s+area+is%22%2BmyRect.area%28%29%29%3B%7D)
what is wrong with the following program?ublic class SomethingIsWrong {public static void main(String[] args){Rectangle myRect;myRect.width = 40;myRect.hight =50;System.out.println('myRect's area is"+myRect.area());}
what is wrong with the following program?
ublic class SomethingIsWrong {
public static void main(String[] args){
Rectangle myRect;
myRect.width = 40;
myRect.hight =50;
System.out.println('myRect's area is"+myRect.area());
}
what is wrong with the following program?ublic class SomethingIsWrong {public static void main(String[] args){Rectangle myRect;myRect.width = 40;myRect.hight =50;System.out.println('myRect's area is"+myRect.area());}
Rectangle myRect;
这里没初始化,改成
Rectangle myRect = new Rectangle(这里输入构造方法的参数,如果没参数就不用输);
记住,要用到一个实例,必须先实例化一个实例.