码迷,mamicode.com
首页 > 其他好文 > 详细

第十一周上机练习

时间:2020-05-14 15:01:02      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:load   pac   run   package   gets   extends   ade   style   bsp   

package t;

public class Vehicle {
    public String brand;
    public String color;
    double speed=0;
    public String getBrand() {
        return brand;
    }
    public void setBrand(String brand) {
        this.brand = brand;
    }
    public String getColor() {
        return color;
    }
    public void setColor(String color) {
        this.color = color;
    }
    public double getSpeed() {
        return speed;
    }
    public void setSpeed(double speed) {
        this.speed = speed;
    }
    public void run(){
        System.out.println("一辆"+this.color+"的"+this.brand+"正在以"+this.speed+"的速度跑");
    }    
}
package t;

public class VehicleTest {

    public static void main(String[] args) {
        Vehicle c=new Vehicle();
        c.brand="benz";
        c.color="black";
        c.run();
    }
}
package t;

public class Car extends Vehicle{
    int loader;

    public int getLoader() {
        return loader;
    }

    public void setLoader(int loader) {
        this.loader = loader;
    }
    public void run(){
        System.out.println("一辆"+this.color+"载客数为"+this.loader+"的"+this.brand+"正在以"+this.speed+"的速度跑");
    }
}
package t;

public class Test {

    public static void main(String[] args) {
        Car c=new Car();
        c.brand="Honda";
        c.color="red";
        c.loader=2;
        c.run();
    }
}

 

第十一周上机练习

标签:load   pac   run   package   gets   extends   ade   style   bsp   

原文地址:https://www.cnblogs.com/sehnsucht/p/12888507.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!