package com.itheima.test
public class DataDemo {
public static void main(String[] args) {
Point p = new Point();
p.x = 10;
p.y = 20;
int x = 10;
int y = 20;
PointTools pointTools = new PointTools();
System.out.println("这里传递的是基本数据类型.....基本");
pointTools.change(x,y);
System.out.println(x + " - "+ y);
System.out.println(p.x + "-" + p.y);
System.out.println("这里传递的是引用数据类型.-------引用");
pointTools.change(p);
System.out.println(x + " - "+ y);
System.out.println(p.x + "-" + p.y);
System.out.println("通过他们的输出结果,你发现了什么?");
}
}
class Point {
int x;
int y;
}
class PointTools {
void change(Point p) {
p.x = 100;
p.y = 200;
}
void change(int x , int y){
x = 150;
y = 250;
}
}
|