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

子类父类构造函数

时间:2019-06-11 19:43:41      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:ati   font   null   oid   str   print   span   ase   函数   

class Base {

private String name = "base";

public Base() {
tellName();
printName();
}

public void tellName() {
System.out.println("Base tell name: " + name);
}

public void printName() {
System.out.println("Base print name: " + name);
}
}


public class Dervied extends Base {

private String name = "dervied";

public Dervied() {
tellName();
printName();
}

public void tellName() {
System.out.println("Dervied tell name: " + name);
}

public void printName() {
System.out.println("Dervied print name: " + name);
}

public static void main(String[] args){

new Dervied();
}
}
-----------------------------------------------

Dervied tell name: null
Dervied print name: null
Dervied tell name: dervied
Dervied print name: dervied



子类父类构造函数

标签:ati   font   null   oid   str   print   span   ase   函数   

原文地址:https://www.cnblogs.com/2016-cxp/p/11005287.html

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