真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

隱式調(diào)用父類的構(gòu)造函數(shù)-創(chuàng)新互聯(lián)

代碼如下:

成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比白水網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式白水網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋白水地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴。

Person.cs文件。

using System;
using System.Collections.Generic;
using System.Text;

namespace InheritDemo
{
   public class Person
   {
       private string id;
       public string Id
       {
           get
           {
               return id;
           }
           set
           {
               id = value;
           }
       }
       private string name;
       public string Name
       {
           get
           {
               return name;
           }
           set
           {
               name = value;
           }
       }
       private int age;
       public int Age
       {
           get
           {
               return age;
           }
           set
           {
               age = value;
           }
       }
       private string gender;
       public string Gender
       {
           get
           {
               return gender;
           }
           set
           {
               gender = value;
           }
       }
         public Person(string name1, int age1, string gender1)
       {
           name = name1;
           age = age1;
           gender = gender1;
       }
       public void Display()
       {
           Console.WriteLine("{0}是{1}性,年齡為{2}",this.name,this.gender,this.age);
       }

   }

   public class Student : Person
   {
       private string class1;
       public string Class
       {
           get
           {
               return class1;
           }
           set
           {
               class1 = value;
           }
       }
       private string department;
       public string Department
       {
           get
           {
               return department;
           }
           set
           {
               department = value;
           }
       }
       private string no;
       public string No
       {
           get
           {
               return no;
           }
           set
           {
               no = value;
           }
       }
        public void Study()
       {
           Console.WriteLine("學(xué)生在學(xué)校學(xué)習(xí)。");
           Console.Read();
       }
   }
}

Program.cs文件。

using System;
using System.Collections.Generic;
using System.Text;

namespace InheritDemo
{
   class Program
   {
       static void Main(string[] args)
       {
           Person objPerson = new Person("XXX",XX,"X");
           objPerson.Display();
           Student objStudent = new Student();
           objStudent.Name = "XXX";
           objStudent.Age = XX;
           objStudent.Gender = "X";
           objStudent.Class = "XXXXXXXXX";
           objStudent.Display();
           Console.Read();
       }
   }
}

錯(cuò)誤:“Person”方法沒有采用“0”個(gè)參數(shù)的重載。

原因:子類的構(gòu)造函數(shù)沒有使用base指明調(diào)用父類哪個(gè)構(gòu)造函數(shù)。

解決辦法:

using System;
using System.Collections.Generic;
using System.Text;

namespace InheritDemo
{
   public class Person
   {
       private string id;
       public string Id
       {
           get
           {
               return id;
           }
           set
           {
               id = value;
           }
       }
       private string name;
       public string Name
       {
           get
           {
               return name;
           }
           set
           {
               name = value;
           }
       }
       private int age;
       public int Age
       {
           get
           {
               return age;
           }
           set
           {
               age = value;
           }
       }
       private string gender;
       public string Gender
       {
           get
           {
               return gender;
           }
           set
           {
               gender = value;
           }
       }
       public Person() { }  //隱式的調(diào)用,base(),父類要提供無參的構(gòu)造函數(shù)。
       public Person(string name1, int age1, string gender1)
       {
           name = name1;
           age = age1;
           gender = gender1;
       }
       public void Display()
       {
           Console.WriteLine("{0}是{1}性,年齡為{2}",this.name,this.gender,this.age);
       }

   }

   public class Student : Person
   {
       private string class1;
       public string Class
       {
           get
           {
               return class1;
           }
           set
           {
               class1 = value;
           }
       }
       private string department;
       public string Department
       {
           get
           {
               return department;
           }
           set
           {
               department = value;
           }
       }
       private string no;
       public string No
       {
           get
           {
               return no;
           }
           set
           {
               no = value;
           }
       }
       public Student() { }  //隱式的調(diào)用,base(),父類要提供無參的構(gòu)造函數(shù)。
       public void Study()
       {
           Console.WriteLine("學(xué)生在學(xué)校學(xué)習(xí)。");
           Console.Read();
       }
   }
}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。


網(wǎng)頁標(biāo)題:隱式調(diào)用父類的構(gòu)造函數(shù)-創(chuàng)新互聯(lián)
路徑分享:http://weahome.cn/article/cocggd.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部