编写一个java应用程序,设计一个汽车类vehicle,包含的属性有车轮个数wheels和车重weight。小车类car是vehicle的子类,其中包含的属性有载人数loader。卡车类truck是car类的子类,其中包含的属性有载重量payload。每个类都有构造方法和输出相关数据的方法。定义一个接口canfly,描述会飞的方法public void fly();分别定义类飞机和鸟,实现canfly借口。定义一个测试类,测试飞机和鸟,在main()方法中创建飞机对象和鸟对象,让飞机和鸟起飞现在想好好学了 请好心人帮帮忙吧
*
* @author monitor
* Created on 2010-12-23, 19:26:20
*//**
* 汽车
* @author monitor
*/
class Vehicle{
public int wheels;
public int weight; public Vehicle(){
} public Vehicle(int wheels,int weight){
this.wheels=wheels;
this.weight=weight;
} public int getWeight() {
return weight;
} public void setWeight(int weight) {
this.weight = weight;
} public int getWheels() {
return wheels;
} public void setWheels(int wheels) {
this.wheels = wheels;
}
}/**
* 小车
* @author monitor
*/
class Car extends Vehicle{
public int loader; public Car(){
} public Car(int wheels,int weight,int loader){
super(wheels,weight);
this.loader=loader;
} public int getLoader() {
return loader;
} public void setLoader(int loader) {
this.loader = loader;
}
}/**
* 卡车
* @author monitor
*/
class Truck extends Car{
private int payload; public Truck(){
} public Truck(int wheels,int weight,int loader,int payload){
super(wheels,weight,loader);
this.payload=payload;
} public int getPayload() {
return payload;
} public void setPayload(int payload) {
this.payload = payload;
}
}/**
* 会飞接口
* @author monitor
*/
interface Canfly{
public void fly();
}/**
* 飞机
* @author monitor
*/
class Plane implements Canfly{ public Plane(){
} public void fly() {
System.out.println("飞机起飞了");
}
}/**
* 小鸟
* @author monitor
*/
class Bird implements Canfly{ public Bird(){
} public void fly() {
System.out.println("小鸟飞起来了");
}}/**
* 测试类
* @author monitor
*/
public class ClassTest {
public static void main(String[] args){
Plane plane=new Plane();
plane.fly();
Bird bird=new Bird();
bird.fly();
}
}