امثلة على الوراثة INHERITANCE في لغة TypeScript
-
2020-10-14
- | daafoor
- | مشاهدات: 486
الوراثة Inheritence :
تسمح لنا الوراثة بتحديد تصنيف(class) يرث جميع التوابع والخصائص من class أخر.
الكلاس الاب الرئيسي يسمى parent class او base class
الكلاس الابن يسمى Child class او derived class
مثال عن الوراثة :
class Car {
Color:string
constructor(color:string) {
this.Color = color
}
}
class Audi extends Car {
Price: number
constructor(color: string, price: number) {
super(color);
this.Price = price;
}
display():void {
console.log("Color of Audi car: " + this.Color);
console.log("Price of Audi car: " + this.Price);
}
}
let obj = new Audi(" Black", 8500000 );
obj.display();
مثال عن الوراثة متعددة المستويات :
class Animal {
eat():void {
console.log("Eating")
}
}
class Dog extends Animal {
bark():void {
console.log("Barking")
}
}
class BabyDog extends Dog{
weep():void {
console.log("Weeping")
}
}
let obj = new BabyDog();
obj.eat();
obj.bark();
obj.weep()
هذه المادة الدراسية هي ضمن مكتبة
مكتبة تمارين و امثلة بلغة البرمجة تايب سكربت TypeScriptمحتاج مساعدة؟ تواصل مع مدرس اونلاين الان!
التعليقات
لا يوجد تعليقات
لاضافة سؤال او تعليق على المشاركة يتوجب عليك تسجيل الدخول
تسجيل الدخول
تسجيل الدخول