91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

隱式調用父類的構造函數

發布時間:2020-05-30 23:00:52 來源:網絡 閱讀:759 作者:韓小妞 欄目:編程語言

代碼如下:

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("學生在學校學習。");
            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();
        }
    }
}

錯誤:“Person”方法沒有采用“0”個參數的重載。

原因:子類的構造函數沒有使用base指明調用父類哪個構造函數。

解決辦法:

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() { }  //隱式的調用,base(),父類要提供無參的構造函數。
        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() { }  //隱式的調用,base(),父類要提供無參的構造函數。
        public void Study()
        {
            Console.WriteLine("學生在學校學習。");
            Console.Read();
        }
    }
}

 

 

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

龙泉市| 云霄县| 乌兰察布市| 华宁县| 廊坊市| 麟游县| 大丰市| 芒康县| 兴山县| 甘肃省| 海安县| 蓬溪县| 定日县| 宜兰县| 桦南县| 洪江市| 岳普湖县| 游戏| 敦化市| 丹江口市| 南澳县| 金堂县| 会同县| 威远县| 岗巴县| 柘城县| 洞头县| 饶阳县| 东乡族自治县| 木里| 九龙坡区| 通城县| 正蓝旗| 平利县| 枣阳市| 乌拉特后旗| 昌图县| 阿克苏市| 五莲县| 会泽县| 新民市|