子类父类构造函数
Posted 2016-cxp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了子类父类构造函数相关的知识,希望对你有一定的参考价值。
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
以上是关于子类父类构造函数的主要内容,如果未能解决你的问题,请参考以下文章