1.The transfer of a parameter
2.The variable parameter(可变参数)(The amount of parameter is uncertain)
public class Person(){
public eat(int a){
a++;
}
}
publci class Myclass(){
Person p = new Person();
int a = 10;
eat(10);
System.out.println("a =" +a);
// a = 10
}
We can find that in the class Myclass,if we System.out.println("a = "+a);
a is still 10;
1.The transfer of parameter in Java -- the transfer of a value(值传递)
Through the above description,we can find that the transfer of parameter in Java is just pass a copied value not the a itself(its address).
2.The variable parameter
We can define a variable parameter by this way:
public class Person(){
public void test4(String ... args){
// String[] args = String ... args
for(int i = 0; i < args.length; i++)
System.out,println(args[i]);
}
}
Then we can access this array by this way
public class Myclass(){
Person p = new Person();
p.test4("Merry","Jack","Bob")
// It will display :
//Merry
//Jack
//Bob
}