C#中base的作用


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _05base關鍵字
{

//顯示的調用父類的構造函數
//調用父類中的重名方法
class Program
{
static void Main(string[] args)
{
Student s = new Student();
Console.ReadKey();
}
}
public class Person
{
public void Test()
{
Console.WriteLine("我是父類");
}
}
public class Student:Person
{
public /*new*/ void Test()//new在子類中隱藏父類繼承過來的方法
{
base.Test();
Console.WriteLine("我是子類");
}
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM