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

C#-তে বেস (Base) এবং ডেরাইভড (Derived) ক্লাস

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

উদাহরণস্বরূপ, Vehicle বেস ক্লাস এবং এর ডেরাইভড ক্লাসগুলো:

Truck Bus Motorbike

ডেরাইভড ক্লাস বেস ক্লাসের মেম্বার ভেরিয়েবল এবং মেম্বার মেথড ইনহেরিট করে।

এভাবে, Shape ক্লাসের জন্য ডেরাইভড ক্লাস হতে পারে Rectangle, নিচের উদাহরণের মতো:

উদাহরণ

using System; 
namespace Program { 
    class Shape { 
        public void setWidth(int w) { width = w; } 
        public void setHeight(int h) { height = h; } 
        protected int width; 
        protected int height; 
    } 
    // ডেরাইভড ক্লাস 
    class Rectangle : Shape { 
        public int getArea() { 
            return (width * height); 
        } 
    } 
    class Demo { 
        static void Main(string[] args) { 
            Rectangle Rect = new Rectangle(); 
            Rect.setWidth(5); 
            Rect.setHeight(7); 
            // অবজেক্টের এরিয়া প্রিন্ট 
            Console.WriteLine("মোট এরিয়া: {0}", Rect.getArea()); 
            Console.ReadKey(); 
        } 
    } 
}

আউটপুট

মোট এরিয়া: 35
  1. C#-এ কালেকশন ক্লাস (Collection Classes) কী?

  2. C#-এ ক্লাস (Classes) কী?

  3. জাভাতে ক্লাসের বিভিন্ন প্রকার কী কী?

  4. পাইথনে বেস ওভারলোডিং মেথডগুলো কী কী?