is there a multi inheritance with C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

is there a multi inheritance with C#

c#

7th Nov 2016, 9:33 PM
Mohamed Ayachi
Mohamed Ayachi - avatar
2 Answers
0
You can'tt inherit multiple classes, but can inherit multiple interfaces
7th Nov 2016, 9:42 PM
Максим Кошевой
Максим Кошевой - avatar
0
Short answer : no. Long answer : No, but it only means you cannot avec 2 classes from which it inherits. Interfaces were (kinda) created to face this issue. Interfaces aren't objects, they cannot be instanciated and they don't have a constructor. But they define variables and functions that can be implemented. For instance, if you want to create a bird, and say it's both an animal and a flying thing, you can create a Bird class that extends Animal and implements Flying. Flying would be an interface in which there could be a flyingSpeed, a flyingAltitude, some functions if you want by example to check if you object isCurrentlyFlying()... Here, the Flying interface could also be used for, say, a plane.
7th Nov 2016, 10:49 PM
Pierre Varlez
Pierre Varlez - avatar