简体   繁体   中英

What is MultiLayer Inheritence in C#?

Is it like a class can inherit from both an Interface and a base class ?

Probably you mean multilevel inheritance , but it's just a chain of classes inheriting, starting from some base class.

It's like this example class structure:

public class Vehicle { ... } // base class
public class CombustionVehicle : Vehicle { ... } // intermediary class
public class Truck : CombustionVehicle { ... } // derived class

The Truck instance is still a Vehicle , so it still can use it's properties and methods (of course if the access modifier allows it).

I think you are confused here by the term multi layer .

multiple inheritance is not supported in C#. A class cannot directly inherit from more than one base class.

C# supports multilevel inheritance, which means that a class can inherit from a class that itself inherits from another class. For example:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM