REUSE! A key advantage of inheritance is being able to reuse a class to specify
ID: 3536591 • Letter: R
Question
REUSE!A key advantage of inheritance is being able to reuse a class to specify your own.
In our programs, we use simple classes to get the concept across
but in real programming projects, if someone has created, tested, and documented a class that is complex,
just think about how much work and effort you would save it you could just use that ready-made class
and add a few members to create a class that is all your own.
That is an example of reusing a BASE class to create your own DERIVED class
Can anyone think or find out what other advantages there are for using inheritance? REUSE!
A key advantage of inheritance is being able to reuse a class to specify your own.
In our programs, we use simple classes to get the concept across
but in real programming projects, if someone has created, tested, and documented a class that is complex,
just think about how much work and effort you would save it you could just use that ready-made class
and add a few members to create a class that is all your own.
That is an example of reusing a BASE class to create your own DERIVED class
Can anyone think or find out what other advantages there are for using inheritance?
Explanation / Answer
Another benefit is that you can have several slightly different objects (say a car class and a truck class that both inherit from a vehicle class) and treat them all as the same object type in some ways (the vehicle). For instance, you could get the value, color, make, model, etc. without having to worry about whether it is specifically a truck or car. In other instances, you could use the differences between them as necessary. Another example is to have two types of messages (picture and text). These would display differently, but they could both inherit from a base message class, which would have a display method. Then you could just treat all message types as just a regular "message" but have them act appropriately when you call the display function, since you could implement these differently in each sub-class.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.