類別繼承範例

#C#

Posted by Phyxsius on 2023-09-14

using System.Security.Cryptography.X509Certificates;

internal class Program
{
    private static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");

        B b = new B("x",100);
        b.show();

        C c = new C("y",200);
        c.show();
    }
}

class A
{
    public A(string a, int b)
    {

    }

    public void show()
    {
        Console.WriteLine("A  Class");
    }
}

class B:A
{
    public B(string x, int y) : base(x,y)
    {

    }
}

class C:B
{
    public C(string x, int y):base(x,y)
    {

    }

    public new void show()
    {
        Console.WriteLine("C  Class");
    }
}

#C#







Related Posts

筆記:淺談 JavaScript 頭號難題 this:絕對不完整,但保證好懂

筆記:淺談 JavaScript 頭號難題 this:絕對不完整,但保證好懂

自學程式設計與電腦科學入門實戰:Git 與 Github 版本控制基本指令與操作入門教學

自學程式設計與電腦科學入門實戰:Git 與 Github 版本控制基本指令與操作入門教學

發生在 GitHub conflict 的衝突——無法發 PR 合併分支

發生在 GitHub conflict 的衝突——無法發 PR 合併分支


Comments