方法的调用

package oop;

public class Demon03 {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	//实际参数与形式参数的类型要一一对应
	int add=Demon03.add(1,2);
	System.out.println(add);
}
public static int add(int a,int b) {
	return a+b;
}

}

java是值传递
package oop;

public class Demon04 {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	int a=2;
	System.out.println(a);
	Demon04.change(a);
	System.out.println(a);
}
//返回值为空
public static void change(int a) {
	a=11;
}

}
输出结果:
2
2

posted @ 2025-03-25 21:10  骆驼刺破仙人掌007  阅读(21)  评论(0)    收藏  举报