class NiMingObject
{
public static void main(String[] args)
{
show(new Car())
}
//需求:汽修厂对汽车进行改装,将车的颜色改为黑色,三个轮胎。
public static void show(Car c) //将匿名对象作为实际参数进行传递
{
c.color="black";
c.num=3;
c.run(); :sleepy::sleepy::sleepy::sleepy::sleepy: 如何将run()方法的内容 改为“System.out.println("颜色为"+color+"轮胎数为"+num)”??????
}
}
class Car
{
String color="red";
int num=4;
void run()
{
System.out.println(color+","+num);
}
}
|