PHP 构造方法
因为子类是从父类继承来的,要先有父类对象的初始化才能进一步构造子类
父类:
package test;
public class FatherClass
{
public FatherClass()
{
System.out.println("FatherClass Create");
}
}
子类:
package test;
import test.FatherClass;
public class ChildClass extends FatherClass
{
public ChildClass()
{
System.out.println("ChildClass Create");
}
public static void main(String[] args)
{
FatherClass fc = new FatherClass();
ChildClass cc = new ChildClass(); //当创建子类的时候,会调用父类的构造函数
}
}
输出结果:
C:>java test.ChildClass
FatherClass Create
FatherClass Create
ChildClass Create