ITPub博客

首页 > IT职业 > IT职场 > JAVA入门第二季4-2练习

JAVA入门第二季4-2练习

IT职场 作者:westwolf 时间:2021-09-09 09:05:25 0 删除 编辑

public class Transportation {

    private String transportway;
    private int num;
    public static int n = 1;

    public Transportation(String transportway, int num)
    {
        this.transportway = transportway;
        this.num = num;     
    }

    public void show() 
    {
        System.out.print("No."+ n);
        n++;
        System.out.println(" transportation is taking on " + transportway + ", and the Capacity is " + num);
    }

//recommend to use STATIC class blah blah
static class Bus extends Transportation
{
    public Bus(String a, int b)
    {
        super(a,b);
    }
}

static class Ship extends Transportation
{
    public Ship(String a ,int b) 
    {
        super(a,b);
    }
}

static class Airplane extends Transportation
{
    public Airplane(String a ,int b) 
    {
        super(a,b);
    }
}

static class Subway extends Transportation
{
    public Subway(String a ,int b) 
    {
        super(a,b);
    }
}

static class Car extends Transportation
{
    public Car(String a ,int b) 
    {
        super(a,b);
    }
}

public static void main(String[] args) 
    {
    Bus bus = new Bus("Land", 40);
    Ship ship = new Ship("Sea", 500);
    Airplane airplane = new Airplane("Sky", 300);
    Subway subway = new Subway("Underground", 200);
    Car car = new Car("Street", 4);

    bus.show();
    ship.show();
    airplane.show();
    subway.show();
    car.show();
    }
}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4662/viewspace-2807974/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-26

  • 博文量
    307
  • 访问量
    21677