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

Extends Demo

时间:2016-09-27 17:50:18      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

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);

}

}

Extends Demo

标签:

原文地址:http://www.cnblogs.com/mabel/p/5913577.html

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