• Extends Demo


    package

    demo.extend;

     

    class Vehicle {

    String type = "4w";

    int maxSpeed = 100;

     

    Vehicle(){

    System.out.println("this is a father construtor");

    }

     Vehicle(String type, int maxSpeed){

    this.type = type;

    this.maxSpeed = maxSpeed;

     

    System.out.println("this is another father construtor");

    }

     

    package

    demo.extend;

     

    class

    Car extends Vehicle {

     

    private String trans;

     

    Car(String trans) {

    this.trans = trans;

    System.out.println("this is a son constructor");

    }

     

    Car(String type, int maxSpeed, String trans) {

    super(type, maxSpeed);

    // this(trans);

    this.trans = trans;

    // this.type = type;

    // this.maxSpeed = maxSpeed;

     

    System.out.println("this is another son constructor");

    }

     

    public static void main(String[] args) {

    Car c1 = new Car("Auto");

     

    Car c2 = new Car("4w", 150, "Manual");

     

    System.out.println(c1.type + " " + c1.maxSpeed + " " + c1.trans);

     

    System.out.println(c2.type + " " + c2.maxSpeed + " " + c2.trans);

    }

    }

  • 相关阅读:
    linux格式化新硬盘并挂载,设置开机自动挂载
    各大名企的笔试面试题
    web2.0 Color
    选调生面试题
    网站流量概要分析
    css下拉菜单演示
    子查询
    技巧
    CMM与软件生命周期
    学习方法之PHP
  • 原文地址:https://www.cnblogs.com/mabel/p/5913577.html
Copyright © 2020-2023  润新知