亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

this指定調用構造函數完了,為什么還會執行沒有指定的構造函數?

this指定調用構造函數完了,為什么還會執行沒有指定的構造函數?

楊__羊羊 2019-03-13 15:19:47
class BaseClass{    public BaseClass()    {        Console.WriteLine("基類構造函數");    }    public BaseClass(string str)    {        Console.WriteLine("基類構造函數,參數:{0}",str);    }}class Something:BaseClass{   //設定SomeClass類不帶參數的構造函數自動調用SomeClass(string str)構造函數,    //并未str參數提供一個默認值:Something    public Something():this("something")    {        Console.WriteLine("調用Something()構造函數");    }    //設定SomeClass(string str)構造函數自動調用SomeClass(string str,int val)構造函數    //并為val參數提供一個默認值:10    public Something (string str):this(str,10)    {        Console.WriteLine("調用Something(string str)構造函數");    }    public Something(string str,int val)    {        Console.WriteLine("調用SomeClass(string str,int val)構造函數");    }}class ClassExample{    public static void Main()    {        Something child = new Something("something");        Console.Read();    }}//初始化類的時候使用的是SomeClass(string str)構造函數,因此會先調用SomeClass(string str, int val)構造函數,這里程序應該執行完了,為什么還會繼續執行SomeClass(string str )構造函數?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 431 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號