- Hands-On Object:Oriented Programming with C#
- Raihan Taher
- 254字
- 2021-07-02 12:44:42
Inheritance
The word inheritance means receiving or deriving something from something else. In real life, we might talk about a child inheriting a house from his or her parents. In that case, the child has the same power over the house that his parents had. This concept of inheritance is one of the pillars of OOP. In programming, when one class is derived from another class, this is called inheritance. This means that the derived class will have the same properties as the parent class. In programming terminology, the class from which another class is derived is called the parent class, while the classes that inherit from these are called child classes.
Let's look at an example:
public class Fruit {
public string Name { get; set; }
public string Color { get; set; }
}
public class Apple : Fruit {
public int NumberOfSeeds { get; set; }
}
In the preceding example, we used inheritance. We have a parent class, called Fruit. This class holds the common properties that every fruit has: a Name and a Color. We can use this Fruit class for all fruits.
If we create a new class, called Apple, this class can inherit the Fruit class because we know that an apple is a fruit. The properties of the Fruit class are also properties of the Apple class. If the Apple inherits the Fruit class, we don't need to write the same properties for the Apple class because it inherits these from the Fruit class.
- Learning Cython Programming
- Effective C#:改善C#代碼的50個有效方法(原書第3版)
- Visual Basic程序設計(第3版):學習指導與練習
- C語言從入門到精通(第4版)
- Spring實戰(第5版)
- Java EE 7 Performance Tuning and Optimization
- SQL基礎教程(第2版)
- Natural Language Processing with Java and LingPipe Cookbook
- C語言程序設計與應用(第2版)
- Java EE架構設計與開發實踐
- 交互設計師成長手冊:從零開始學交互
- Learning Shiny
- Visual FoxPro程序設計
- Python大數據與機器學習實戰
- Visual FoxPro程序設計