Harmony Clean Flat Responsive WordPress Blog Theme

Assignment 12

Review Questions:
  1. Describe a situation where dynamic binding is a great advantage over its absence.
  • The third characteristic (after abstract data types and inheritance) of objectoriented programming languages is a kind of polymorphism3 provided by the dynamic binding of messages to method definitions.
2. What is a virtual method?
  • A virtual method is a declared class method that allows overriding by a method with the same derived class signature. Virtual methods are tools used to implement the polymorphism feature of an object-oriented language, such as C#. When a virtual object instance method is invoked, the method to be called is determined based on the object’s runtime type, which is usually that of the most derived class.
3. What is an abstract method? What is an abstract class?
  • Such a method is often called an abstract method ( pure virtual method in C++). A class that includes at least one abstract method is called an abstract class (abstract base class in C++). Such a class usually cannot be instantiated, because some of its methods are declared but are not defined (they do not have bodies).
4. Describe briefly the eight design issues used in this chapter for object- oriented languages.
  •  A number of issues must be considered when designing the programming language features to support inheritance and dynamic binding. Those that we consider most important are discussed in this section.
5. What is a nesting class?
  • A nesting class is a class defined inside another class.
Problem Sets:
1. Compare the multiple inheritance of C++ with that provided by interfaces in Java.
  • C#, which is based on C++ and Java, supports object-oriented programming. Objects can be instantiated from either classes or structs. The struct objects are stack dynamic and do not support inheritance. Methods in a derived class can call the hidden methods of the parent class by including base on the method name. Methods that can be overridden must be marked virtual, and the overriding methods must be marked with override. All classes (and all primitives) are derived from Object.
2. What is one programming situation where multiple inheritance has a significant advantage over interfaces?
  • A situation when there are two classes derived from a common parent and they have a child.
3. Explain the two problems with abstract data types that are ameliorated by inheritance.
  • 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.
4. Describe the categories of changes that a subclass can make to its parent class.
  • Subclasses can add things (variables, methods). Subclass in C++ can effectively remove a method using “private” inheritance. Inherited methods can be overridden.
5. Explain one disadvantage of inheritance.
  • Disadvantage of using inheritance is that the two classes (base and inherited class) get tightly coupled.
    This means one cannot be used independent of each other.