The correct answer is: B. Knowledge of a general category can be applied to more specific objects.
Inheritance is a powerful concept in object-oriented programming that allows you to create new classes from existing classes. The new class inherits all of the properties and methods of the existing class, and you can add new properties and methods to it. This can save you a lot of time and effort, because you don’t have to write all of the code for the new class from scratch.
For example, let’s say you have a class called Animal
. This class has properties for the animal’s name, age, and species. It also has methods for eating, sleeping, and playing. Now, let’s say you want to create a new class called Dog
. This class inherits all of the properties and methods of the Animal
class, but it also has its own properties for the dog’s breed and color. It also has its own methods for barking, wagging its tail, and rolling over.
Inheritance is a very important concept in object-oriented programming. It allows you to create new classes quickly and easily, and it helps you to organize your code in a logical way.
Here is a brief explanation of each option:
A. Classes with the same name must be derived from one another. This is not true. Classes can have the same name, but they do not have to be derived from one another. For example, you could have two classes called Animal
and Dog
, and they would not be related to each other.
B. Knowledge of a general category can be applied to more specific objects. This is the definition of inheritance. When you inherit from a class, you are saying that the new class is a more specific version of the existing class. For example, a Dog
is a more specific type of Animal
.
C. C++ functions may be used only if they have logical predecessors. This is not true. C++ functions can be used without having logical predecessors. For example, you could have a function called print()
that does not have any other functions that call it.
D. One function name may invoke different methods. This is also not true. A function name can only invoke one method. For example, the function print()
can only invoke the method that prints something to the screen.