练习题1:Java引用对象指向练习

时间:2021-07-09 18:09:30   收藏:0   阅读:26

求代码最终的输出结果:str、a、p、array

 public class Test {
  public static void main(String[] args) {
  String str = "hello";
  Integer a = 1;
  Point p = new Point(1,2);
  Point[] array = {
  new Point(3,4),
  new Point(5,6),
  new Point(7,8)
  };
  test(str,a,p,array);
  System.out.println(str);
  System.out.println(a);
  System.out.println(p);
  System.out.println(Arrays.toString(array));
  }
  public static void test(String str,Integer a,Point p,Point[] array){
  str = str.substring(1);
  a++;
  a=20;
  p.setX(2);
  array[0].setX(a);
  Point[] array2 = Arrays.copyOf(array, array.length+1);
  array2[array2.length-1]=p;
  array2[0].setX(5);
  array = array2;
  array[array2.length-1].setX(6);
  p = new Point(7,8);
  }
 }
 

输出结果:

  hello
  1
  Point [x=6, y=2]
  [Point [x=5, y=4], Point [x=5, y=6], Point [x=7, y=8]]

解答:

技术分享图片

 

原文:https://www.cnblogs.com/XiaoCui-blog/p/14990717.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!