কম্পিউটার টিউটোরিয়াল

C#-এ Java-এর Super কীওয়ার্ডের সমতুল্য: base কীওয়ার্ড

জাভার super কীওয়ার্ডের সমতুল্য C#-এ base কীওয়ার্ড। এটি বেস ক্লাসের কনস্ট্রাক্টর, মেথড বা প্রোপার্টি অ্যাক্সেস করতে ব্যবহৃত হয়।

উদাহরণ

using System;

public class Animal
{
    public string repColor = "brown";
}

public class Reptile : Animal
{
    string repColor = "green";

    public void Display()
    {
        Console.WriteLine("Color: " + base.repColor); // বেস ক্লাসের
        Console.WriteLine("Color: " + repColor);      // ডেরাইভড ক্লাসের
    }
}

public class Demo
{
    public static void Main()
    {
        Reptile rep = new Reptile();
        rep.Display();
    }
}

আউটপুট

Color: brown
Color: green

base কীওয়ার্ড কনস্ট্রাক্টর চেইনিং-এও ব্যবহার হয়: public Derived() : base(param) { }

  1. জাভাতে অ্যাবস্ট্রাক্ট ক্লাস

  2. জাভাতে ফাইনাল ক্লাস

  3. জাভাতে final কীওয়ার্ড

  4. জাভাতে super কীওয়ার্ড