第十四周

package dmk2;

public class Vehicle {
    String brand;
    String colour;
    double speed; 
    public Vehicle(String brand, String colour, double speed) {
        super();
        this.brand = brand;
        this.colour = colour;
        this.speed = 0;
    }
    public String getBrand() {
        return brand;
    }
    public String getColour() {
        return colour;
    }
    public void setColour(String colour) {
        this.colour = colour;
    }
    public double getSpeed() {
        return speed;
    }
    public void setSpeed(double speed) {
        this.speed = speed;
    }
    public Vehicle() {
        super();
    }
    
    public void run(){
        System.out.println(brand+"品牌"+colour+"色的车正以"+"速度"+speed+"在行驶");
    }
    public static void main(String[] args) {
        
        // TODO Auto-generated method stub
        Vehicle v=new Vehicle("benz","black",100);
        v.setSpeed(120);
        v.run();

    }

}
package dmk2;

public class Car extends Vehicle{
    int loader;
    


    public int getLoader() {
        return loader;
    }



    public void setLoader(int loader) {
        this.loader = loader;
    }



    public Car(String brand, String colour, double speed, int loader) {
        super(brand, colour, speed);
        this.loader = loader;
    }



    

    public Car() {
        super();
        // TODO Auto-generated constructor stub
    }



    public Car(String brand, String colour, double speed) {
        super(brand, colour, speed);
        // TODO Auto-generated constructor stub
    }
    
    
    public void run(){
        System.out.println(brand+"品牌"+colour+"色的车正以"+"速度"+speed+"在行驶"+"该车载人数为"+loader+"人");
    }


    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Car c=new Car("honda","red",100,2);
        c.setSpeed(100);
        c.setLoader(2);
        c.run();
        

    }

}

posted @ 2021-06-18 15:18  董梦坤  阅读(28)  评论(0编辑  收藏  举报