Binus Alam Sutera

Binus Alam Sutera

Sunday, January 25, 2015

Chapter 12 Answers

Nama: Christian Gunawan
NIM: 1801384174

Kali ini saya akan menjawab Assignment #12 dari Chapter 12 Programming Language Concepts R Sebesta :

Review Questions #6-10 :

6. Describe a situation where dynamic binding is a great advantage over its absence.

There is a base class, A, that defines a method draw that draws some figure associated with the base class. A second class, B, is defined as a subclass of A. Objects of this new class also need a draw method that is like that provided by A but a bit different. With overriding, we can directly modify B’s draw function. But without it, we either make a specific function in A for B and inherit it.


7. 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.


8. What is an abstract method? What is an abstract class?

An abstract method is a method which all descendant classes should have. An abstract class is a class which has abstract method.


9. Describe briefly the eight design issues used in this chapter for object-oriented languages.
-What non-objects are in the language?
-Are Subclasses Subtypes? If so, derived objects can be legally used wherever a parent object could be used.
-Type Checking and Polymorphism
-Single and Multiple Inheritance. Inherit from 1 (or more than 1) parent.
-Object Allocation and Deallocation. Are objects allocated from heap or stack.
-Dynamic and Static Binding. When are messages bound to methods, before or during run-time?
-Nested Classes. Can a class be nested inside another class?
-Initialization of Objects. Are objs init'd when created? Implicit or explicit?


10. What is a nesting class?

A nesting class is a class defined inside another class.


Problem Set #6-10 :

6. Compare the multiple inheritance of C++ with that provided by interfaces in Java.

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.


7. What is one programming situation where multiple inheritance has a significant advantage over interfaces?

When two or more parent classes are derived from one grandparent class and has one child (diamond problem).


8. 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.


9. 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.


10. Explain one disadvantage of inheritance.

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