public class Rect{
double width,height,area;
void setWidth(double width){
if (width>0){
this.width=width;
}
}
void setHeight(double height){
if (height>0){
this.height=height;
}
}
double getWidth(){
return width;
}
double getHeight(){
return height;
}
double getArea(){
area=width*height;
return area;
}
}
public class Example4_4 {
public static void main(String args[]){
Rect rect=new Rect();
double w = 12.76,h = 25.28;
rect.setHeight(w);
rect.setWidth(h);
System.out.println("矩形对象的宽"+rect.getWidth()+"高"+rect.getHeight());
System.out.println("矩形的面积"+rect.getArea());
System.out.println("更改向对象的方法参数传递值得w、h变量的值为100和256");
w=100;
h=256;
System.out.println("矩形对象的宽"+rect.getWidth()+"高"+rect.getHeight());
}
}
为什么w和h都改变了数值,但是第二次的宽和高的数值还是没有改变的样子?这个传值的机制是什么意思?