2013-06-27

Programming Language Concept (11)

Book : Concept of Programming Language

Page 519
Review Question
1. What are the two kinds of abstractions in programming languages ?
- Process Abstraction and Data Abstraction

2. Define abstract data type .
- A data structure in the form of a record, but which includes subprograms that manipulate its data.

3. What are the advantages of the two parts of the definition of abstract data type ?
- Increased reliability, Reduces range of code and number of variables which a programmer must be aware when writing / reading part of program. Make name conflict less likely to happen

5. What are the language design issues for abstract data types ?
- ADTs must have a function that allows a user to modify a value inside that data type. Although the method is public, the value itself must be private.

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

11. What is the use of the Ada use clause ?
- To eliminate the need for explicit qualification of the references to entities from the named package.

12. What is the fundamental difference between a C++ class and an Ada package ?
- Class must be accessed from an instance of itself while package can be accessed directly.

13. From where are C++ objects allocated ?
- From heap

15. What is the purpose of a C++ destructor ?
- To deallocate heap space the object used.

16. What are the legal return types of a destructor ?
- destructor has no return type

21. What are initializers in Objective-C?
- Constructors that must be explicitly called.

26. Why does Java not have destructors ?
- Because Java has its own implicit garbage collection.

Page 520
Problem Set  
2. Suppose someone designed a stack abstract data type in which the function top returned an access path (or pointer ) rather than returning a copy of the top element. This is not a true data abstraction. Why ? Give an example that illustrates the problem.
- The problem with this is that the user is given access to the stack through the returned value of the “top” function. For example, if p is a pointer to objects of the type stored in the stack, we could have:
p = top(stack1);
*p = 42;
These statements access the stack directly, which violates the principle of a data abstraction.

4. What are the advantages of the nonpointer concept in Java ?
- Variable Access are absolutely defined by the programmer
- No memory leak (i.e. dangling pointers, nameless variables etc)

9. What happens if the constructor is absent in Java and C++ ?
- The compiler will automatically make a default one


11. Why is the destructor of C# rarely used ?
- Because C# has its own garbage collection method , just like Java

Tidak ada komentar:

Posting Komentar