Q6 : Compare the multiple inheritance of C++ with that provided by interfaces in Java.
A : C++ inheritance is implementation inheritance. That is, a class inheriting from two of more superclasses actually inherits the code from those classes. Java’s interface mechanism is an interface inheritance. That is, a class implementing two or more interfaces simply inherits (and must provide its own implementations for) the methods of the interface.
Q7 : What is one programming situation where multiple inheritance has a significant advantage over interfaces?
A : When two or more parent classes are derived from one grandparent class and has one child (diamond problem).
Q8 : Explain the two problems with abstract data types that are ameliorated by inheritance.
A : The problems solved are reusability of code and "extensibility". Reusability because one won't have to copy/paste his code from one data type to another, allowing for a greater readability. Extensibility because a method can accept a certain class as an argument, and get a child class of this one. This will allow the user to have a wider set of functionality, but the method will still be able to know that the entities it relies on are present.
Q9 : Describe the categories of changes that a subclass can make to its parent class.
A : Subclasses can add things (variables, methods). Subclass in C++ can effectively remove a method using "private" inheritance. Inherited methods can be overridden.
Q10 : Explain one disadvantage of inheritance.
A : Language & implementation complexity. The shared inheritance problem of multiple inheritance. Subclass is dependent upon its base class (which might change over time).
No comments:
Post a Comment