C# এ একাধিক উত্তরাধিকার সমর্থিত নয়৷ একাধিক উত্তরাধিকার প্রয়োগ করতে, ইন্টারফেস ব্যবহার করুন।
এখানে আমাদের ইন্টারফেস পেইন্টকস্ট ক্লাস আকারে −
public interface PaintCost {
int getCost(int area);
} আকৃতি হল আমাদের বেস ক্লাস যেখানে আয়তক্ষেত্র হল প্রাপ্ত শ্রেণী -
class Rectangle : Shape, PaintCost {
public int getArea() {
return (width * height);
}
public int getCost(int area) {
return area * 80;
}
} আসুন এখন C# −
-এ একাধিক উত্তরাধিকারের জন্য ইন্টারফেস বাস্তবায়নের সম্পূর্ণ কোডটি দেখি।Using System;
namespace MyInheritance {
class Shape {
public void setWidth(int w) {
width = w;
}
public void setHeight(int h) {
height = h;
}
protected int width;
protected int height;
}
public interface PaintCost {
int getCost(int area);
}
class Rectangle : Shape, PaintCost {
public int getArea() {
return (width * height);
}
public int getCost(int area) {
return area * 80;
}
}
class RectangleDemo {
static void Main(string[] args) {
Rectangle Rect = new Rectangle();
int area;
Rect.setWidth(8);
Rect.setHeight(10);
area = Rect.getArea();
// Print the area of the object.
Console.WriteLine("Total area: {0}", Rect.getArea());
Console.WriteLine("Total paint cost: ${0}" , Rect.getCost(area));
Console.ReadKey();
}
}
}