谁能帮我解释一下下面两道题的参数传递过程
publicclassValueReference{inta=10;publicstaticvoidmain(String[]args){ValueReferenceaV...
public class ValueReference {
int a=10;
public static void main(String[] args) {
ValueReference aValue=new ValueReference();
aValue.print();
}
public void print()
{
int b=a;
System.out.println("Before changed value a="+a+",b="+b);
a=30;
System.out.println("After changed value a="+a+",b="+b);
}
}
public class Student {
String strName;
public static void main(String[] args) {
Student aStudent=new Student();
aStudent.setStudentName("张三");
System.out.println("aStudent name is "+aStudent.getStudentName());
Student bStudent=aStudent;
bStudent.setStudentName("李四");
System.out.println("bStudent name is "+bStudent.getStudentName());
String name=aStudent.getStudentName();
System.out.println("After bStudent the aStudent name is "+name);
}
public String getStudentName(){
return strName;
}
public void setStudentName(String name){
strName=name;
}
} 展开
int a=10;
public static void main(String[] args) {
ValueReference aValue=new ValueReference();
aValue.print();
}
public void print()
{
int b=a;
System.out.println("Before changed value a="+a+",b="+b);
a=30;
System.out.println("After changed value a="+a+",b="+b);
}
}
public class Student {
String strName;
public static void main(String[] args) {
Student aStudent=new Student();
aStudent.setStudentName("张三");
System.out.println("aStudent name is "+aStudent.getStudentName());
Student bStudent=aStudent;
bStudent.setStudentName("李四");
System.out.println("bStudent name is "+bStudent.getStudentName());
String name=aStudent.getStudentName();
System.out.println("After bStudent the aStudent name is "+name);
}
public String getStudentName(){
return strName;
}
public void setStudentName(String name){
strName=name;
}
} 展开
2个回答
展开全部
1.基本类型赋值。 b=a=10;之后a=30但是并不改变b的值,所以b还是10;
2.引用赋值。首先引用astudent = 张三,这是没有疑问的 bstudent=astudent 也就是说bstu..的引用指向了astu...的引用,这两个指的是一个东西,那么bstudent指的改变了,astudent也改变了。所以此时astudent&&bstudent = 李四~
不知道你明白没有……
2.引用赋值。首先引用astudent = 张三,这是没有疑问的 bstudent=astudent 也就是说bstu..的引用指向了astu...的引用,这两个指的是一个东西,那么bstudent指的改变了,astudent也改变了。所以此时astudent&&bstudent = 李四~
不知道你明白没有……
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询