Q6 : Describe a situation where dynamic binding is a great advantage over its absence.
A : 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.
Q7 : What is a virtual method?
A : 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.
Q8 : What is an abstract method? What is an abstract class?
A : An abstract method is a method which all descendant classes should have. An abstract class is a class which has abstract method.
Q9 : Describe briefly the eight design issues used in this chapter for object-oriented languages.
A :
-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?
Q10 : What is a nesting class?
A : A nesting class is a class defined inside another class.
No comments:
Post a Comment