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

C#-এ বেস ক্লাস (Base Class) কী


একটি ক্লাস তৈরি করার সময়, সম্পূর্ণ নতুন ডেটা মেম্বার এবং মেম্বার ফাংশন লিখার বদলে, প্রোগ্রামার নির্দিষ্ট করতে পারে যে নতুন ক্লাসটি একটি বিদ্যমান ক্লাসের মেম্বার ইনহেরিট করবে। এই বিদ্যমান ক্লাসকে বেস ক্লাস বলা হয়, এবং নতুন ক্লাসকে ডেরাইভড ক্লাস বলা হয়।

একটি ক্লাস একাধিক ক্লাস বা ইন্টারফেস থেকে ডেরাইভড হতে পারে, অর্থাৎ এটি একাধিক বেস ক্লাস বা ইন্টারফেস থেকে ডেটা এবং ফাংশন ইনহেরিট করতে পারে।

C#-এ বেস ক্লাসের সিনট্যাক্স

<access-specifier> class <base_class> {
    ...
}
class <derived_class> : <base_class> {
    ...
}

উদাহরণ

using System;

namespace InheritanceApplication
{
    class Shape
    {
        public void setWidth(int w)
        {
            width = w;
        }
        public void setHeight(int h)
        {
            height = h;
        }
        protected int width;
        protected int height;
    }

    // Derived class
    class Rectangle : Shape
    {
        public int getArea()
        {
            return (width * height);
        }
    }

    class RectangleTester
    {
        static void Main(string[] args)
        {
            Rectangle Rect = new Rectangle();
            Rect.setWidth(5);
            Rect.setHeight(7);
            // Print the area of the object.
            Console.WriteLine("Total area: {0}", Rect.getArea());
            Console.ReadKey();
        }
    }
}

  1. C#-এ সিলড ক্লাস (Sealed Class) কী এবং এর ব্যবহার

  2. C#-এ ইনহেরিটেন্স কী?

  3. C#-এ Array ক্লাস কী?

  4. dry-rb এক্সপ্লোর করুন: ১৮+ রুবি জেম জন্য রোবাস্ট, রি-ইউজেবল কোড