久久综合丝袜日本网手机版,日韩欧美中文字幕在线三区,亚洲精品国产品国语在线,极品在线观看视频婷婷

      • 函數(shù)覆蓋總結(jié)知識(shí)點(diǎn)

        時(shí)間:2022-06-25 00:21:05 總結(jié)范文 我要投稿
        • 相關(guān)推薦

        函數(shù)覆蓋總結(jié)知識(shí)點(diǎn)

          一個(gè)虛函數(shù)被覆蓋后,任何父類變量都不能訪問(wèn)該虛函數(shù)的具體實(shí)現(xiàn)。

        函數(shù)覆蓋總結(jié)知識(shí)點(diǎn)

          public virtual void IntroduceMyself(){...}//父類虛函數(shù)

          public new void IntroduceMyself(){...}//子類覆蓋父類虛函數(shù)

          using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace MethodOverrideByNew{ public enum Genders { Female=0, Male=1 } public class Person { protected string _name; protected int _age; protected Genders _gender; ///

          /// 父類構(gòu)造函數(shù) ///

          public Person() { this._name = "DefaultName"; this._age = 23; this._gender = Genders.Male; } ///

          /// 定義虛函數(shù)IntroduceMyself() ///

          public virtual void IntroduceMyself() { System.Console.WriteLine("Person.IntroduceMyself()"); } ///

          /// 定義虛函數(shù)PrintName() ///

          public virtual void PrintName() { System.Console.WriteLine("Person.PrintName()"); } } public class ChinesePerson :Person{ ///

          /// 子類構(gòu)造函數(shù),指明從父類無(wú)參構(gòu)造函數(shù)調(diào)用起 ///

          public ChinesePerson() :base(){ this._name = "DefaultChineseName"; } ///

          /// 覆蓋父類方法IntroduceMyself,使用new關(guān)鍵字修飾虛函數(shù) ///

          public new void IntroduceMyself() { System.Console.WriteLine("ChinesePerson.IntroduceMyself()"); } ///

          /// 重載父類方法PrintName,使用override關(guān)鍵字修飾虛函數(shù) ///

          public override void PrintName(){ System.Console.WriteLine("ChinesePerson.PrintName()"); } } class Program { static void Main(string[] args) { //定義兩個(gè)對(duì)象,一個(gè)父類對(duì)象,一個(gè)子類對(duì)象 Person aPerson = new ChinesePerson(); ChinesePerson cnPerson = new ChinesePerson(); //調(diào)用覆蓋的方法,父類對(duì)象不能調(diào)用子類覆蓋過(guò)的方法,只能調(diào)用自身的虛函數(shù)方法 aPerson.IntroduceMyself(); cnPerson.IntroduceMyself(); //調(diào)用重載方法,父類對(duì)象和子類對(duì)象都可以調(diào)用子類重載過(guò)后的方法 aPerson.PrintName(); cnPerson.PrintName(); System.Console.ReadLine(); } }}

          結(jié)果:

          Person.IntroduceMyself()

          ChinesePerson.IntroduceMyself()

          ChinesePerson.PrintName()

          ChinesePerson.PrintName()

          以上這篇C# 函數(shù)覆蓋總結(jié)學(xué)習(xí)(推薦)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持。

        【函數(shù)覆蓋總結(jié)知識(shí)點(diǎn)】相關(guān)文章:

        初中函數(shù)知識(shí)點(diǎn)總結(jié)07-29

        關(guān)于函數(shù)與方程的知識(shí)點(diǎn)總結(jié)10-17

        二次函數(shù)知識(shí)點(diǎn)總結(jié)07-03

        函數(shù)中自變量的知識(shí)點(diǎn)總結(jié)08-02

        二次函數(shù)知識(shí)點(diǎn)總結(jié)12-19

        初中數(shù)學(xué)所有函數(shù)的知識(shí)點(diǎn)總結(jié)11-22

        高二數(shù)學(xué)函數(shù)公式知識(shí)點(diǎn)總結(jié)06-28

        高中函數(shù)基本性質(zhì)知識(shí)點(diǎn)總結(jié)07-25

        高一數(shù)學(xué)函數(shù)知識(shí)點(diǎn)總結(jié)12-01

        高中數(shù)學(xué)函數(shù)知識(shí)點(diǎn)最新總結(jié)07-02