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/05/10 20:12:30
whatiswrongwiththefollowingprogram?ublicclassSomethingIsWrong{publicstaticvoidmain(String[]args){Rec

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(这里输入构造方法的参数,如果没参数就不用输);
记住,要用到一个实例,必须先实例化一个实例.