[Java] 纯文本查看 复制代码
//汽车类
public class Car {
public Car() {
// TODO Auto-generated constructor stub
}
public Car(String temp) {
// TODO Auto-generated constructor stub
this.setTemp(temp);
}
//发动机类
class Engine {
//工作功能
public void work(Car c) {
//判断
if(c.getTemp().equals("运行")) {
System.out.println("发动机飞速旋转");
} else if(c.getTemp().equals("停止")) {
System.out.println("发动机停止工作");
}else {
}
}
}
//状态
private String temp;
public String getTemp() {
return this.temp;
}
public void setTemp(String temp) {
this.temp = temp;
}
}
public class Test {
public static void main(String[] args) {
Car.Engine ce = new Car().new Engine();
ce.work(new Car("运行"));
ce.work(new Car("停止"));
}
}