day06-对象内存图-引用类型对象作为方法参数

This commit is contained in:
2026-05-10 13:14:22 +08:00
parent e026c0bc5d
commit f761934d91

View File

@@ -19,7 +19,8 @@ public class Demo03 {
System.out.println(p1.color); System.out.println(p1.color);
System.out.println(p1.price); System.out.println(p1.price);
System.out.println(p1.size);*/ System.out.println(p1.size);*/
p1.show(); //p1.show();
showPhone(p1);
//对象的行为操作 //对象的行为操作
p1.call("10086"); p1.call("10086");
@@ -36,9 +37,19 @@ public class Demo03 {
System.out.println(p2.color); System.out.println(p2.color);
System.out.println(p2.price); System.out.println(p2.price);
System.out.println(p2.size);*/ System.out.println(p2.size);*/
p2.show(); //p2.show();
showPhone(p2);
p2.call("10000"); p2.call("10000");
p2.sendMsg("13666666666"); p2.sendMsg("13666666666");
} }
//能不能定义一个方法:接收一个手机对象,展示它的所有属性
//注意使用了引用数据类型作为参数传递地址如果是基本数据类型4类8种传递值
public static void showPhone(Phone phone) {
System.out.println(phone.brand);
System.out.println(phone.color);
System.out.println(phone.price);
System.out.println(phone.size);
}
} }