What type of inheritance has the following syntax? Syntax class A { // body of the class A. } class B : access-specifier A { // body of class B. } class C : access-specifier A { // body of class C. } a. Multilevel Inheritance b. Multiple Inheritance c. Hierarchical Inheritance d. Hybrid Inheritance
时间: 2024-03-18 15:40:32 浏览: 70
class-of-builtins.rar_class
The given syntax represents Hierarchical Inheritance. Hierarchical Inheritance is a type of inheritance in which multiple derived classes are created from a single base class. In the given syntax, class B and class C are both derived from class A. Therefore, it represents Hierarchical Inheritance.
In Hierarchical Inheritance, a single base class is inherited by multiple derived classes, and each derived class can add its own features to the inherited ones. For example:
```
class Animal {
// base class members
};
class Dog : public Animal {
// derived class members
};
class Cat : public Animal {
// derived class members
};
```
In this example, `Dog` and `Cat` are derived from the `Animal` base class using Hierarchical Inheritance. Therefore, the correct answer is c. Hierarchical Inheritance.
阅读全文