day06-面向对象-成员变量和局部变量的区别

This commit is contained in:
2026-01-19 10:19:21 +08:00
parent 54e8600789
commit 138e09fba1
2 changed files with 31 additions and 24 deletions

View File

@@ -8,27 +8,17 @@ public class Demo03 {
p1.price = 4999;
p1.size = 5.5;
p1.color = "星空黑";
//展示下对应手机的属性
/*System.out.println(p1.brand);
System.out.println(p1.price);
System.out.println(p1.size);
System.out.println(p1.color);*/
showPhone(p1);
p1.show();
System.out.println("---------");
//买一台土豪金的尺寸6.1价格8999的苹果手机
Phone p2 = new Phone();
p2.brand = "苹果";
p2.price = 8999;
p2.size = 6.1;
p2.color = "土豪金";
//展示下对应手机的属性
/*System.out.println(p2.brand);
System.out.println(p2.price);
System.out.println(p2.size);
System.out.println(p2.color);*/
showPhone(p2);
p2.show();
}
//在非描述类的类中定义方法一般加上static