zoukankan      html  css  js  c++  java
  • 继承(extends)

    1.  继承:遗传   

    2.  语法        

      public class 子类 extends 父类{

                 }   

    例:public class DDDDG extends Pte {              

                }   

    3.  继承的特点       

      a.子类可以继承父类的非私有的属性和方法       

      b.不能继承构造方法       

      c.继承默认权限修饰符的方法和属性,子类和父类必需在同一包中   

    4.  super(父类)      

      super.属性名  //表示访问父类的属性      

      super.方法名(参数); //表示访问父类的方法      

      super(参数);//表示访问父类的构造函数;      

      注意:super()访问父类构造函数时,必需写在第一行

    package 二期三章练习4;
    
    public class Bus extends MotoVehicle {
        private int seatCount;
        int money = 0;
        public Bus(){
            
        }
        public Bus(String no,String brand,int seatCount){
            super(no,brand);
            this.seatCount = seatCount;
        }
        
        public int getSeatCount() {
            return seatCount;
        }
        public void setSeatCount(int seatCount) {
            this.seatCount = seatCount;
        }
        public int calRent(int days){
            if(seatCount > 16){
                money = days*1500;
            }else{
                money = days*800;
            }
            return money;
        }
    }
    View Code
  • 相关阅读:
    BAT脚本批量调用Sql执行文件 (SqlServer 数据库)
    树莓派系统刻录到首次登陆等问题
    数据库视图的使用
    MQ配置安装
    PLSQL集合类型
    PLSQL-包函数存储过程
    Oracle 字段拆分替换在合并成一条
    ORACLE-EXP和IMP方法介绍
    javascript几个月前的时间
    返回顶部实现方式
  • 原文地址:https://www.cnblogs.com/liumeilin/p/7018936.html
Copyright © 2011-2022 走看看