package com.Summer_042701.cn;
/**
* @author Summer
* 项目需求:通过抽象类实现以下功能
* 定义抽象类:交通工具TrafficTool
* 属性:载客量
* 方法:行驶()
* 子类:飞机(plane)
* 方法:行驶()飞机在天上飞
* 子类:汽车(car)
* 方法:行驶()汽车路上行驶
*/
class TestTrafficTool{//测试类
public static void main(String[] args) {
plane p = new plane(200);
p.run();
car1 c = new car1(100);
c.run();
}
}
abstract class TrafficTool {
private int count;
public TrafficTool(int count) {
this.count=count;
}
public int getCount() {
return count;
}
abstract void run();//构建抽象方法
}
class plane extends TrafficTool{
public plane(int count) {
super(count);
}
@Override
void run() {
System.out.println("飞机在天上飞"+getCount());
}
}
class car1 extends TrafficTool{
public car1(int count) {
super(count);
}
@Override
void run() {
System.out.println("汽车路上行驶"+getCount());
}
}