Computer Science 3675
Summer 2004
Additional practice questions for final exam

  1. Write a clearly legible T to the left of each of the following that is true, and a clearly legible F to the left of each that is false.

    1. The class is an important concept of object-based programming. F

    2. In most object-oriented languages, some type checking must be done at run time. T

  2. In object-oriented programming, is a private data field of an object accessible only to that one object, or is it possible for other objects to access it directly?

    No. A private data field (variable) in object x can be seen in all objects that have the same class as x.

  3. Are most object oriented programming languages imperative or declarative languages?

    Object-oriented languages are primarily imperative. The point of an object is to group variables with the functions that modify them, so we need to have variables and the capability of modifying them.

  4. If a method is declared to be protected in class A, Where is that method visible?

    It is visible in class A and all of its subclasses.

  5. What is the difference between a class variable and an instance variable?

    An instance variable is part of an instance of a class, and each instance gets its own copy of the variable. A class variable is associated with the class itself, and all instances of the class share that variable.

  6. The base class B of a class A is the class that A directly extends. In a single-inheritance object-oriented language, is there a limit on the number of base classes that a class can have?

    In a single-inheritance language, each class can only have one base class. That means that the hierarchy diagram is a tree.

  7. In object-oriented programming, you imagine that objects carry functions with them. Yet, the functions are not really stored with the objects. How does an object locate its functions? How does it know which functions to select? What is the name of the system support that is responsible for locating functions?

    An object carries a tag indicating its class. A method is found by dynamic method selection: the class tag and the method name or number are used to look up the method in the dispatch table.

  8. Variables are found by means of selectors. How does the mechanism for inheriting variables work in single-inheritance object-oriented languages? Is there a separate implementation of each selector for each class, or does one implementation of each selector work for all subclasses of a class? How do the selector(s) work?

    In a single-inheritance language, each variable is found at the same position in the memory that represents an object, regardless of the class of the object. So a single selector works, and it does not need to examine the tag of the object. It looks in a given position.

  9. What is an abstract class?

    An abstract class is a class that has at least one virtual method. It has no constructors, so you can never build an object that has just this class. You can only build objects of subclasses of an abstract class.

  10. What are the characteristics of a virtual method? What makes it virtual?

    A virtual method is declared in a class that is higher in the class hierarchy than the level where the method can be implemented. It is implemented in subclasses. You can think of a virtual method as describing part of an abstract data type, without committing to any implementation or semantics of that abstract data type.