匿名对象(考点)
创建N个相同属性和行为的car
car c1 = new car(); car c1 = new car()
c1.color = "red"; |
c1.num = 8 |-----------------method(c1);
c1.run(); |
.......
........------------------------------------method(new car);
........
car c10 = new car();
c10.color = "red";
c10.num = 8;
c10.run();
-----------------------抽取相同属性,行为形成方法----------------------------------------
public static void method(car cc){ //cc地址值找到new car,并为这个匿名对象赋值,相当于给匿名对 cc.color = "red"; 象起了名字
cc.num = 8;
cc.run();
|
|