কম্পিউটার

C# এ বেস এবং ডিরাইভড ক্লাস কি?


একটি ক্লাস একাধিক শ্রেণী বা ইন্টারফেস থেকে উদ্ভূত হতে পারে, যার অর্থ হল এটি একাধিক বেস ক্লাস বা ইন্টারফেস থেকে ডেটা এবং ফাংশনগুলি উত্তরাধিকার সূত্রে পেতে পারে৷

উদাহরণস্বরূপ, নিম্নলিখিত প্রাপ্ত ক্লাস সহ যানবাহন বেস ক্লাস।

Truck
Bus
Motobike

প্রাপ্ত শ্রেণীটি বেস ক্লাস সদস্য ভেরিয়েবল এবং সদস্য পদ্ধতিগুলিকে উত্তরাধিকারসূত্রে পায়।

একইভাবে, শেপ ক্লাসের জন্য প্রাপ্ত শ্রেণীটি নিম্নলিখিত উদাহরণের মতো আয়তক্ষেত্র হতে পারে।

উদাহরণ

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;
   }
   // Derived class
   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);
         // Print the area of the object.
         Console.WriteLine("Total area: {0}", Rect.getArea());
         Console.ReadKey();
      }
   }
}

আউটপুট

Total area: 35

  1. C# এ সংগ্রহের ক্লাস কি কি?

  2. C# এ ক্লাস কি কি?

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

  4. পাইথনে বেস ওভারলোডিং পদ্ধতি কি কি?