1.匿名对象就是没有名字的对象,如果程序中只是用一次该对象,就可以使用匿名对象的方式
引用传递
1.范例
class Ref{
int temp=10;
}
public class F02 {
public static void main(String args[]) {
Ref r1=new Ref();
r1.temp=20;
System.out.println(r1.temp);
tell(r1);
System.out.println(r1.temp);
}
public static void tell(Ref r2) {
r2.temp=30;
}
}

public class F03 {
public static void main(String[] args) {
String str1="hello";
System.out.println(str1);
tell(str1);
System.out.println(str1);
}
public static void tell(String str2) {
str2="word";
}
}

String数值类型不可改变的原因。
class Ref2 {
String temp="hello";
}
public class F04 {
public static void main(String[] args) {
Ref2 r1= new Ref2();
r1.temp="word";
System.out.println(r1.temp);
tell(r1);
System.out.println(r1);
}
public static void tell(Ref2 r2) {
r2.temp ="happy";
}
}

网友评论