Rabu, 26 Juni 2013

Chap 11 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta

CONCEPTS OF
PROGRAMMING LANGUAGES
TENTH EDITION
Robert W. Sebesta
Chapter 11-Abstract Data Type and Encapsulation
Review Question

1. What are the two kinds of abstraction in programming languages?
Answer: The two kinds of abstraction in programming languages are process abstraction and data abstraction.

2. Define abstract data type.
Answer: Abstract data type is a data structure that include its data member and also member function that process its data.

6 . Explain how information hiding is provided in Ada package.
Answer: Data type representations can appear in the package specification but be hidden from clients by putting them in the private clause of the package. The abstract type itself is defined to be private in the public part of the package specification. Private types have built-in operations for assignment and comparison for equality and inequality.

10. What is the use of the Ada with clause ?
Answer: To make the names defined in external packages visible

15. What is the purpose of a C++ destructor?
Answer: Destructor in C++ can be used to print a value of some or all of the object's data members dan it can deallocate an object from a class.

16. What are the legal return types of a destructor?
Answer: there are no legal return from a destructor and constructor. It is like void function that has no return value.

20. What is the use of limited private types?
Answer: An alternative to private types is a more restricted form: limited private types. Nonpointer limited private types are described in the private section of a package specification, as are nonpointer private types. The only syntactic difference is that limited private types are declared to be limited private in the visible part of the package specification. The semantic difference is that objects of a type that is declared limited private have no built-in operations. Such a type is useful when the usual predefined operations of assignment and comparison are not meaningful or useful. For example, assignment and comparison are rarely used for stacks.

21. What are initializers in Objective-C?
Answer: The initializers in Objective-C are constructors.

22. What is the use of @private and @public directives?
Answer: The use is to specify the access levels of the instance variables in a class definition.

27. Where are all Java methods defined?
Answer: All Java methods are defined in a class.

37. What is the name of all Ruby constructors?
Answer: Constructors in Ruby are named initialize.

43. What is a C++ namespace, what is its purpose?
Answer: In general, a namespace is a container for a set of identifiers and allows the disambiguation of homonym identifiers residing in different namespaces. The purpose is to help programs manage the problem of global namespace.

Problem Set:

4. What are the advantages of the nonpointer concept in Java?
Answer:
Advantages:
-It reduce the chance of memory leak
-No nameless variable
Disadvantage:
-Not allowed to declare pointer variable
-Increase the complexity of task related to data structer like array, structure ect.

9. What happens if the constructor is absent in Java and C++?
Answer:
If there is no constructor in jave and C++ so the compiler will set a default constructor.

10. Which two conditions make data type “abstract”?
Answer:
• The representation of objects of the type is hidden from the program units that use the type, so the only direct operations possible on those objects are those provided in the type’s definition.
• The declarations of the type and the protocols of the operations on objects of the type, which provide the type’s interface, are contained in a single syntactic unit. The type’s interface does not depend on the representation of the objects or the implementation of the operations. Also, other program units are allowed to create variables of the defined type.

11. Why is the destructor of C# rarely used?
Answer: Although C# allows destructors to be defined, because it uses garbage collection for most of its heap objects, destructors are rarely used.

13. Compare and contrast the data abstraction of Java and C++.
Java support for abstract data types is similar to that of C++. There are, however, a few important differences. All objects are allocated from the heap and accessed through reference variables. Methods in Java must be defined completely in a class. A method body must appear with its corresponding method
header. Therefore, a Java abstract data type is both declared and defined in a single syntactic unit. A Java compiler can inline any method that is not overridden. Definitions are hidden from clients by declaring them to be private. Rather than having private and public clauses in its class definitions, in Java access modifiers can be attached to method and variable definitions. If an instance variable or method does not have an access modifier, it has package access.

Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.

Tidak ada komentar:

Posting Komentar