zoukankan      html  css  js  c++  java
  • C# base

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace 继承
    {
        class Program
        {
            static void Main(string[] args)
            {
                Vertebrate vertebrate = new Vertebrate();
                Mammal mammal = new Mammal();
                Human human = new Human("人类");
                vertebrate.Sleep();
                mammal.Sleep();
                human.showmeg();//调用的本身的方法
                human.showmeg1();//调用的基类的方法
            }
        }
        class Mammal : Vertebrate//派生类:基类
        {
            private string arms;
            private string legs;
            private int age;
            public new void Sleep()  //NEW关键字重写Sleep方法   如果不用new 则会继续调用基类中的Sleep方法
            {
                Console.WriteLine("哺乳动物的睡眠");
            }
            public virtual void message()
            {
                Console.WriteLine("我是一只哺乳动物");
            }
        }
        class Human : Mammal//派生类:基类
        {
            private string name;
            public Human(string name)
            {
                this.name = name;
            }
            public override void message()
            {
                Console.WriteLine("我是一个人");
            }
            public void showmeg()
            {
                message();
            }
            public void showmeg1()
            {
                base.message();//调用基类的方法
            }
        }
    }
  • 相关阅读:
    HUD--2553 N皇后问题
    poj--2139
    poj--2236
    poj--2229
    poj--2376 Cleaning Shifts
    poj--3669
    poj--1979 Red and Black
    poj--1258
    经典DP问题--poj1088滑雪
    Poj 1041--欧拉回路
  • 原文地址:https://www.cnblogs.com/BruceKing/p/12068571.html
Copyright © 2011-2022 走看看