m0_67339481 2022-03-30 21:51 采纳率: 16.7%
浏览 60
已结题

java 编写Car类继承于Vehicles是什么意思

img


编写Car类继承于Vehicles是什么意思?什么是继承于?

  • 写回答

2条回答 默认 最新

  • 关注

    Vehicles指交通工具类,交通工具有很多子类。

    public class Vehicles {
    
        private String brand;
        private String color;
        
        public Vehicles() {}
        public Vehicles(String brand,String color) {
            this.brand = brand;
            this.color = color;
        }
        
        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 void run() {
            System.out.println("我已经开动");
        }
        public void showInfo() {
            System.out.println("商标:"+brand+",颜色:" + color);
        }
    }
    
    public class Car extends Vehicles{
    
        private int seats;
        
        
        public int getSeats() {
            return seats;
        }
        public Car() {}
        public Car(String brand,String color,int seats) {
            super(brand,color);
            this.seats = seats;
        }
        
    
        public void setSeats(int seats) {
            this.seats = seats;
        }
    
    
        public void showCar() {
            super.showInfo();
            System.out.println("座位数:"+seats);
        }
    }
    
    
    public class Truck extends Vehicles{
    
        private float load;
        
        public Truck() {}
        public Truck(String brand,String color,float load) {
            super(brand,color);
            this.load = load;
        }
        
        public float getLoad() {
            return load;
        }
    
    
        public void setLoad(float load) {
            this.load = load;
        }
    
        public void showTruck() {
            super.showInfo();
            System.out.println("载重量:" + load);
        }
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月7日
  • 已采纳回答 3月30日
  • 修改了问题 3月30日
  • 创建了问题 3月30日

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog