Review question
2. Define abstract data type.
data type that satisfies the following conditions:
-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.
8. What is the difference between private and limited private types in Ada?
Limited private is more restricted form and objects of a type that is declared limited private have no built-in operations.
10. What is the use of the Ada with clause?
With clause makes the names defined in external packages visible; in
this case Ada. Text_IO, which provides functions for input of text.
11. What is the use of the Ada use clause?
The with clause makes the names defined in external packages Visible.
12. What is the fundamental difference between a C++ class and an Ada package?
Ada packages are more generalize encapsulations that can define any number of types.
15. What is the purpose of a C++ destructor?
The purpose of a C++ desctructor is as a debugging aid, in which case
they simply display or print the values of some or all of the object’s
data members before those members are deallocated.
16. What are the legal return types of a desctructor?
Destructor has no return types and doesn’t use return statements.
20. What is the use of limited private types?
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?
The initializers in Objective-C are constructors.
22. What is the use of @private and @public directives?
The use is to specify the access levels of the instance variables in a class definition.
27. Where are all Java methods defined?
All Java methods are defined in a class.
30. What is a friend function? What is a friend class?
a “friend” of a given class is allowed access to public, private, or
protected data in that class. Normally, function that is defined outside
of a class cannot access such information.
Class that can access the private and protected members of the class
in which it is declared as a friend. On declaration of friend class all member function of the friend class become friends of the class in which the friend class was declared.
Problem set
4. What are the advantages of the nonpointer concept in Java?
Any task that would require arrays, structures, and pointers in C can
be more easily and reliably performed by declaring objects and arrays
of objects. Instead of complex pointer manipulation on array pointers,
you access arrays by their arithmetic indices. The Java run-time system
checks all array indexing to ensure indices are within the bounds of the
array. You no longer have dangling pointers and trashing of memory
because of incorrect pointers, because there are no pointers in Java.
10. Which two conditions make data type “abstract”?
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.
12. How are classes in Ruby made dynamic?
Classes in Ruby are dynamic in the sense that members can be added at
any time. This is done by simply including additional class definitions
that specify the new members. Moreover, even predefined classes of the
language, such as String, can be extended.
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.
19. Compare Java’s packages with Ruby’s modules.
In Ruby, the require statement is used to import a package or a module. For example, the extensions package/module is imported as follows.
require ‘extensions’
External files may be included in a Ruby application by using load or require. For example, to include the external file catalog.rb, add the following require statement.
require “catalog.rb”
The difference between load and require is that load includes the specified Ruby file every time the method is executed and require includes the Ruby file only once.
In Java, the import statement is used to load a package. For example, a Java package java.sql is loaded as follows.
import java.sql.*;
Tidak ada komentar:
Posting Komentar