示例#1
0
        // ClassInheritanApp
        private static void ClassInheritanApp()
        {
            // Test virtual method and override method
            WhiteHuman tom = new WhiteHuman();
            // Convert tom to base class(将 ton 强制转换成基类)
            Human ren = (Human)tom;

            tom.complexion = "white";
            tom.LoveFood();
            tom.Complexion();
            ren.LoveFood();
            Human ren2 = new Human();

            ren2.LoveFood();
        }
        public static HuMan CreateHuman(HumanEnum humanEnum)
        {
            HuMan huMan = null;

            switch (humanEnum)
            {
            case HumanEnum.Black:
                huMan = new BlackHuman();
                break;

            case HumanEnum.White:
                huMan = new WhiteHuman();
                break;

            default:
                throw new NullReferenceException();
            }
            return(huMan);
        }