class pen1 {
static int redValue=1,greenValue=2,blueValue=3;
static void getRGBColor(int red,int green,int blue){
red=redValue;
green=greenValue;
blue=blueValue;
}
}
public class Color1 {
public static void main(String args[]){
int r=-1,g=-1,b=-1;
pen1.getRGBColor(r,g,b);
System.out.println("red="+r+", green="+g+", blue="+b);
}
}
----------------------------------------------------------------
class RGBColor {
public int red,green,blue;
}
class pen2 {
static int redValue=1,greenValue=2,blueValue=3;
static void getRGBColor(RGBColor aColor){
aColor.red=redValue;
aColor.green=greenValue;
aColor.blue=blueValue;
}
}
public class Color2 {
static RGBColor pen2Color=new RGBColor();
public static void main(String args[]){
pen2.getRGBColor(pen2Color);
System.out.println("red="+pen2Color.red+", green="+pen2Color.green+", blue="+pen2Color.blue);
}
}
----------------------------------------------------------------
这两个程序不都是参数传递么,为什么结果却不相同呢,请高手指教~~~