有参和带参的概念:
public class ZhazhiJi {
//在方法中声明一个String类型的变量fruit 后面调用此方法是需要给这个变量赋值
//此方法有一个String类型的返回值
简单的使用:
public String zhazhi ( String fruit ) {
String juice = fruit + "汁";
return juice;
}
}
用测试类调用此方法:
/*调用zhazhi方法*/
public static void main(String[]args){
//创建对象
ZhazhiJi myZhazhiji = new ZhazhiJi();
String myFruit = "苹果";
//创建String 一个变量接收返回值并给之前的方法的形参赋值
String myJuice = myZhazhiji.zhazhi(myFruit);
//打印输出
System.out.println(myJuice);
}
>以上就是形参赋值就是 实参