📄 passbyvalue1.java
字号:
//c3:PassByValue1.java
//author:ZhangHongbin
//This program is protected by copyright laws.
//Pass By Value.
public class PassByValue1
{
int i=0;
PassByValue1(int newValue)
{
i=newValue;
}
static void changeInt(int value)
{
value=98;
System.out.println("value in changeInt()= "+value);
}
static void changeObjRef(PassByValue1 obj)
{
obj=new PassByValue1(99);
System.out.println("obj.i in changeObjRef()= "+obj.i);
}
static void changeObjAttr(PassByValue1 obj)
{
obj.i=100;
System.out.println("obj.i in changeObjAttr()= "+obj.i);
}
public static void main(String[] args)
{
int value=2;
System.out.println("value before changeInt()= "+value);
changeInt(value);
System.out.println("value after changeInt()= "+value);
PassByValue1 obj =new PassByValue1(2);
System.out.println("--------------------------------");
System.out.println("obj before changeObjRef()= "+obj);
System.out.println("obj.i before changeObjRef()= "+obj.i);
changeObjRef(obj);
System.out.println("obj.i after changeObjRef()= "+obj.i);
System.out.println("obj after changeObjRef()= "+obj);
System.out.println("--------------------------------");
System.out.println("obj before changeObjAttr()= "+obj);
System.out.println("obj.i before changeObjAttr()= "+obj.i);
changeObjAttr(obj);
System.out.println("obj.i after changeObjAttr()= "+obj.i);
System.out.println("obj after changeObjAttr()= "+obj);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -