总结之【参数传递】

总结之【参数传递】
1.值传递
  Java中数据类型分为两大类;其中
原始类型数据在调用传递时遵守“值传递”规则。
  例:Public class Student{
  Public void change(int n){
  n = 10;
  }
  Public static void main(String[] args){
  Student stu = new Student();
  int i = 11;
  stu.change(i);
  Syetem.out.println(“i =”+i);
  }
  }
  结果i = 11
2.引用传递
  例:Public static void main(String[] args){
  Student stu1 = new Student();
  stu1.setScore(3);
  Student stu2 = new Student();
  stu2.setScore(4);
  Student stu3 = new Student();
  Stu3.setScore(5);
  stu1 = stu2;
  stu2 = stu3;
  stu3= stu1;
  Score = stu3.getScore();
  Syetem.out.println(“学分为”+Score);
  
  }
  

猜你喜欢

转载自657265691.iteye.com/blog/1977575