本文共 1059 字,大约阅读时间需要 3 分钟。
package test.extend;public class Base { public Base(){ System.out.println("基类构造"); say(); } public void say(){ System.out.println("我是基类"); } public static void main(String[] args) { Base base=new Child(); }} class Child extends Base{ public Child(){ System.out.println("子类构造"); say(); } @Override public void say(){ System.out.println("我是子类"); }}
基类构造
我是子类 子类构造 我是子类
public class BaseA { public BaseA() { Function(); } public virtual void Function() { Console.WriteLine("Base::Function"); } } class ChildA :BaseA { public ChildA() { Function(); } public virtual void Function() { Console.WriteLine("Child::Function"); } }运行结果:
Base:Function
Child::Function
class BaseA { BaseA() { Function(); } virtual void Function() { cout<<"Base::Function"; cout<运行结果:
开始做,坚持做,重复做Base:Function
Child::Function
转载地址:http://pbnax.baihongyu.com/