class Car
{
//事物的公共属性使用成员变量描述
String name; //名字
String color; // 颜色
int wheel; // 轮子数
//事物的公共行为使用函数描述
public void run()
{
System.out.println("跑");
}
}
class Demo16
{
public static void main(String[] args)
{
Car c = new Car();
c.name = "BMW";
c.color = "白色";
c.wheel = 3;
c.run();
System.out.println("名字:" + c.name + " 颜色:" + c.color + " 轮子数:" + c.wheel);
}
}
/*
class Car
{
//事物的公共属性
String name;
String color;
int wheel;
//事物的公共行为
public void run()
{
if(wheel >= 4)
{
System.out.println(name + "飞快的跑");
}
else
{
System.out.println(name + "轮子不够,要修");
}
}
}
class CarFactory
{
String name;
String address; // 地址
String tel; // 电话
public Car repair(Car c)
{
if(c.wheel >= 4)
{
System.out.println("不用修");
}
else
{
c.wheel = 4;
System.out.println("修好了");
}
return c;
}
}
class Demo17
{
public static void main(String[] args)
{
Car c = new Car(); // 使用Car声明一个变量c,c变量指向一个车对象
c.wheel = 3;
c.name = "BMw";
System.out.println("名字:" + c.name);
c.run();
CarFactory f = new CarFactory();
f.name = "小强修车厂";
c = f.repair(c);
c.run();
}
}
*/