(day4)Write a pair of Poker--The transfer of parameter.

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
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 7,965评论 0 0
  • 本文转载自知乎 作者:季子乌 笔记版权归笔记作者所有 其中英文语句取自:英语流利说-懂你英语 ——————————...
    Danny_Edward阅读 44,024评论 4 38
  • 亲子日记32 9月8日 今天星期六,大宝早晨起来吃完饭我送他去托辅了,早晨我先带他去买的数学口算题卡,到了托辅许多...
    马佳浩妈妈阅读 1,400评论 0 0
  • 一大早的就好困,困到不想睁眼,这几天就感觉像过了三年之久,真的,可能任何人都无法体会这种感觉,工资想要来,不知道怎...
    千柠千柠阅读 1,567评论 0 2
  • 一转眼,2019马上就要过去了,回想起2019所发生的事情还真是美好啊! 星期五下午最后一节...
    cb8fd21f28b9阅读 1,040评论 0 0

友情链接更多精彩内容