Concept of Programming Language Chapter 12

Review Questions
1. Name two functional languages that support object-oriented programming.
– C++ and Objective-c

2. What are the problems associated with programming using abstract data types ?
– in nearly all cases, the features and capabilities of the existing type are not quite right for the new
use. The old type requires at least some minor modifications.

3. What is the advantage of inheritance ?
– Allows to reuse ADT and modificate it without actually modifying the original ADT and program organization problem.

4. What is message protocol ?
– Entire collection of methods of an object.

5. What is an overriding method ?
– A new method that overrides inherited method(i.e. Changes how the method behaviors compared to the inherited one)

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 dynamic dispatch ?
-kind of polymorphism provided by the dynamic binding of messages to method definitions.

8. What is an abstract method ? What is an abstract class ?
– a method which all descendant classes should have. An abstract class is a class which has abstract method.

10. What is an inner class ?
– Non-static classes that are nested directly in another class

11. What is the message protocol of an object ?
– Colletions of an object’s methods.

12. From where are Smalltalk objects allocated ?
– From the heap

38. What is Boxing ?
– Coercion of primitive values when they are put in object context

52. Does Ruby support multiple inheritance ?
– No. it does not

Problem Set

2. In what ways can “compatible “ be defined for the relationship between an overridden method and the overriding method ?
– in ways of its formal definition, the parameters and return types.

3. Compare the inheritance of C++ and Java.
– In Java, all objects are Inherited, either directly or indirectly. While in C++ a class can be defined to stand on its own without an ancestor.

– In Java, there’s no access level specifier of inheritance, while C++ has private public and protected.

– In Java, the functions are virtual by default. While in C++ the functions CAN BE MADE virtual with the keyword virtual

7. What is one programming situation where multiple inheritance has a significant disadvantage over interfaces ?
– When two or more parent classes are derived from one grandparent class and has one child. (diamond problem)

9. Given an example of inheritance in C++, where a subclass overrides the superclass methods.
– class human{
public :
void eat(){std::cout<<”Eating”;}
}
class man : public human{
public :
void eat(){std::cout<<”Eat like a boss”;}
}

10. Explain one advantage of inheritance
– Allows programmer to reuse a class with modifications that doesn’t apply to the initial class, so both class can still be used. This also improves readability and writability.

14. Explain type checking in Java
-Type checking happens before execution. Type checking can only uses type information that have declared in your program, and not the possible type that an object has at runtime. Java checks all line of code to make sure that it uses values correctly according to the declared types.

16. State why Java is said to be more pure object oriented than C++.
-Because Java implements pure class. Every function / statements in Java is run by a class. While in C++ not all functions are run by a class.

17. What are the different options for object destruction in Java ?
– Using Close method or Finalize method.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s