什么叫形参和实参?请编写一个程序说明

来源:百度知道 编辑:UC知道 时间:2024/06/17 13:24:37

public class TestOverLoad {
void sum(int a , int b) {
int c=a+b;//这里a、b就是形参
System.out.println( "二数之和是"+ c);
}
public static void main(String[] args) {
TestOverLoad t = new TestOverLoad();
t.sum(3, 4);
double a = 3.0;
double b = 4.0;
t.sum(a, b);//这里a、b就是实参
}
}

int f(int a,int b) //a,b就叫形参
{
return a+b;
}

void main()
{
int x,y;
cin>>x>>y;
cout<<f(x,y)<<endl;//x,y 叫实参
}