初级传值调用```
package demo;
public class Text {
void f(int m)
{
m=20;
System.out.println(m);
}
public static void main(String[] args) {
Text t=new Text();
int a=10;
int b=20;
t.f(a);
System.out.println(a);
}
}
对象的引用
package demo;
public class Text {
int x,y;
Text (int x,int y)
{
this.x=x;
this.y=y;
}
void f4(Text al)
{
al.x=100;
int m=10;
System.out.println(m);
System.out.println(al.x);
}
public static void main(String[] args) {
Text a=new Text(3,4);
Text b=new Text(5,6);
a.f4(b);
System.out.println(b.x);
System.out.println(a.x);
}
}
```**此程序输出
10
100
100
3**
## 变式
```java
package demo;
public class Text {
int x,y;
Text (int x,int y)
{
this.x=x;
this.y=y;
}
void f4(Text al)
{
al.x=100;
int m=10;
this.x=200;
System.out.println(m);
System.out.println(al.x);
}
public static void main(String[] args) {
Text a=new Text(3,4);
Text b=new Text(5,6);
a.f4(a);
System.out.println(b.x);
System.out.println(a.x);
}
}
10
200
5
200
变式2
package demo;
public class Text {
int x,y;
Text (int x,int y)
{
this.x=x;
this.y=y;
}
void f4(Text al)
{
al.x=100;
int m=10;
this.x=200;
System.out.println(m);
System.out.println(al.x);
}
public static void main(String[] args) {
Text a=new Text(3,4);
Text b=new Text(5,6);
a.f4(b);
System.out.println(b.x);
System.out.println(a.x);
}
}
10
100
100
200