public class Rectangle {
private double a;
private double b;
public Rectangle(){
this.a = 0;
this.b = 0;
}
public Rectangle(double a,double b){
this.a = a;
this.b = b;
}
public double getRectangleA(){
return a;
}
public double getRectangleB(){
return b;
}
double s = a*b
public void print(){
System.out.print(s);
}
}
....
public class Test9 {
public static void main(String[] args) {
Rectangle rt = new Rectangle(2.0, 4.0);
rt.print();
}
}
这是我封装的矩形类,然后在对象实例化调用print()方法,输出结果为0.0;而将double s= a * b删掉,直接在print()方法中system。out。print(a*b),输出结果是对的,这是什么原因啊? |
|