📄 argumenttest.java
字号:
class Location{
int x,y;
}
class Point{
int x,y;
Point( ){
x=20;
y=30;
}
void getXY( int xValue, int yValue ){
xValue=x;
yValue=y;
}
void getLocation( Location lReference ){
lReference.x=x;
lReference.y=y;
}
}
public class ArgumentTest{
public static void main( String args[ ] ){
Point p=new Point( );
int xValue=-1, yValue=-1;
System.out.println("Pass by value:");
p.getXY(xValue,yValue);
System.out.println("xValue = "+xValue+" yValue = "+yValue);
Location l=new Location( );
p.getLocation( l ); //label 2 : pass by reference
System.out.println("Pass by reference:");
System.out.println("l.x = "+l.x+" l.y = "+l.y);
}
}
运行结果为:
C:\>java ArgumentTest
Pass by value:
xValue = -1 yValue = -1
Pass by reference:
l.x = 20 l.y = 30
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -