其他分享
首页 > 其他分享> > 第十四周

第十四周

作者:互联网

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();
        

    }

}

标签:String,colour,public,第十四,loader,speed,brand
来源: https://www.cnblogs.com/dmk1/p/14899685.html