首页 > 其他 > 详细

Extends Demo

时间:2016-09-27 17:49:12      阅读:183      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!