---
# System prepended metadata

title: Review Test (Theme 1)

---

# Review Test (Theme 1)

The assignment of values to global variables, which is usual in imperative languages

-   A. is also possible in declarative languages like Haskell.
-   B. Enables the possibility of side effects, considered harmful and a main problem of imperative languages.
-   C. Can be avoided in object-oriented languages if variables are defined to be public attributes.
-   D. Is not allowed in structured languages like C or Pascal.

*   `Answer Key:B`

Reflection is a feature of some programming languages which is very useful in metaprogramming, but what is metaprogramming?

-   A. It is a technique for which two processes are allocated in the main memory of the computer so that they can be concurrently executed by the processor or CPU.
-   B. It is a very high level language to define programming languages.
-   C. It is the ability to write programs that write or manipulate other programs (even them- selves) as data.
-   D. It is cooperative programming, i.e., several programmers cooperate to write a program.

*   `Answer Key:C`

The routine that automatically deals with memory management during program execution is called:

-   A. Runtime monitor.
-   B. Memory allocator.
-   C. Garbage collector.
-   D. Dispatcher.

*   `Answer Key:C`

Given the following definition of a Java class Parcial1:
public class Parcial1&lt;T,K&gt; { }
which of the following sentences is TRUE.

-   A. It defines an abstract class where T can be instantiated with subclasses of K only.
-   B. It defines a generic class where K can be instantiated with subclasses of T only.
-   C. It defines a generic class whose parameters are specified when the class is used.
-   D. It is a wrong definition.

*   `Answer Key:C`

With regard to Java's generic classes, which of the following claims is TRUE?

-   A. Only abstract classes are available in Java, generic classes are not allowed.
-   B. A generic class is one that does not implement any of the methods in the class.
-   C. Generic classes are those whose declaration involves at least a type variable. For instance, public class Container&lt;T&gt;.
-   D. Generic classes are those that inherit from some superclass.

*   `Answer Key:C`

Supposing that class B is derived from class A and C&lt;T&gt; is a generic class, which of the following statements is INCORRECT?

-   A. C&lt;A&gt; x = new C&lt;B&gt;();
-   B. C&lt;A&gt; x = new C&lt;A&gt;();
-   C. A x = new A();
-   D. A x = new B();

*   `Answer Key:A`

Which varieties of polymorphism are involved in the following Java code?
int myAdd(int x, int y){ return x+y; }
double myAdd(double x, double y){ return x+y; }
public static void main (String args []){myAdd (3, 3.5);}

-   A. Overloading and inheritance.
-   B. Coercion and overwriting.
-   C. Overloading and coercion.
-   D. Universal and coercion.

*   `Answer Key:C`

Which of the following is NOT a feature of the imperative programming paradigm?

-   A. The emphasis is on “how” to solve a problem.
-   B. Destructive assignment is used.
-   C. The semantics is simpler and control can be automatic.
-   D. Variables are references to the memory of the machine.

*   `Answer Key:C`

Which of the following claims is WRONG?

-   A. A declarative program can be seen as an executable specification.
-   B. An imperative program describes a sequence of changes of state.
-   C. The logic paradigm is based on first-order logic.
-   D. Side-effects are a typical feature of functional languages.

*   `Answer Key:D`

Which of the following claims about programming paradigms is WRONG:

-   A. Deadlocks are a major problem in concurrent programming.
-   B. In OO Programming objects encapsulate state and operations.
-   C. The main goal of parallel programming is running several programs on a single processor.
-   D. Event-driven programs use a main loop which detect and handle the events.

*   `Answer Key:C`

Mark the kind of polymorphism that fits the following definition:
"... functions or operators that share a single name but can be applied to arguments of different types with different implementations depending on the type of the actual parameters."

-   A. Inheritance.
-   B. Overloading.
-   C. Genericity.
-   D. Abstraction.

*   `Answer Key:B`

Which kind of polymorphism is defined by the following Java code?
int myAdd(int x, int y, int z){ ... }
double myAdd(double x, double y, double z){ ... }

-   A. Inheritance.
-   B. Overloading.
-   C. Coercion.
-   D. Genericity.

*   `Answer Key:B`

Reflection permits (mark the FALSE option):

-   A. To obtain and show, during the program execution, the name of all class instances that were created during the execution.
-   B. Reading a string from the keyboard and use such a string to create an object with this name.
-   C. To infer the axiomatic semantics of the language.
-   D. Reading a string from the keyboard and use it to call a method having this name.

*   `Answer Key:C`

Which of the following claims about genericity in Java is WRONG?

-   A. Java permits the definition of generic classes.
-   B. Java permits the definition of generic methods.
-   C. Generic methods can be defined as part of a generic class only.
-   D. Generic classes may have several parameters.

*   `Answer Key:C`

Which of the following claims about Java is TRUE?

-   A. Instances of abstract classes can only be passed as parameters to abstract methods.
-   B. Instances of abstract classes are referred as variables whose type is an abstract class.
-   C. Abstract classes provide multiple inheritance.
-   D. The implementation of inherited methods can be modified by overriding.

*   `Answer Key:D`

Supposing that class B is derived from class A and C&lt;T&gt; is a generic class, which of the following statements is INCORRECT?

-   A. C&lt;A&gt; x = new C&lt;B&gt;();
-   B. C&lt;A&gt; x = new C&lt;A&gt;();
-   C. A x = new A();
-   D. A x = new B();

*   `Answer Key:A`

In the following fragment of Java code:
double myFun(int x, double y){
return x + y;
}
double myFun(double x, double y){
return x \* y;
}
which kind of polymorphism(s) can be found?

-   A. Overloading (only).
-   B. Coercion (only).
-   C. Overloading and genericity.
-   D. Overloading and coercion.

*   `Answer Key:D`

Which of the following statements about programming languages is TRUE:

-   A. Script languages cannot be object-oriented.
-   B. No language can be concurrent and also declarative.
-   C. In an imperative language, function calls may contain variables.
-   D. All the declarative languages are lazy.

*   `Answer Key:C`

Indicate which of the following sentences about concurrent programming is FALSE:

-   A. Semaphores were introduced to synchronize concurrent processes.
-   B. Starvation happens when a process cannot access a resource due to its low priority.
-   C. Deadlock can happen only between three or more processes that access the same resources.
-   D. Data corruption can happen only when two programs write concurrently to the same resource.

*   `Answer Key:C`

Kowalski's sentence "Program = Logic + Control"

-   A. is wrong; he rather said "Program = Data + Algorithms".
-   B. is an alternative designation of Hoare triples from axiomatic semantics.
-   C. it means that the specification of control is the most important issue when writing declarative programs.
-   D. it means that, in declarative programming, programmers can focus on writing the logic of the problem.

*   `Answer Key:D`

Which statement about languages with a type system is FALSE?

-   A. Java is a programming language with implicit typing.
-   B. In programming languages with implicit typing, it is not necessary to give the type of variables, functions, etc.
-   C. In programming languages with explicit typing, it is necessary to give the type of variables, functions, etc.
-   D. In programming languages with polymorphic types (parametric types), type variables are used for the definition of types.

*   `Answer Key:A`

The assignment of values to global variables, which is usual in imperative languages

-   A. is also possible in declarative languages like Haskell.
-   B. Enables the possibility of side effects, considered harmful and a main problem of imperative languages.
-   C. Can be avoided in object-oriented languages if variables are defined to be public attributes.
-   D. Is not allowed in structured languages like C or Pascal.

*   `Answer Key:B`

Which of the following claims is WRONG:

-   A. Reflection can be used in Java by means of a specific library defining methods to inspect classes, interfaces, attributes, etc.
-   B. A bad use of reflection may hinder performance.
-   C. Languages with reflection are all imperative.
-   D. Reflection permits the self-inspection and self-transformation of programs.

*   `Answer Key:C`

For the following inheritance hierarchy:
public class Horse { ... };
public class Pony extends Horse { ... };
and the following code:
Pony p = new Pony();
Horse h = p;
which of the following claims is TRUE?

-   A. The code compiles without any problem.
-   B. Class Horse should be abstract.
-   C. The inheritance relation is wrong: implements should be used instead of extends.
-   D. A compilation error arises.

*   `Answer Key:A`

With regard to Java's generic classes, which of the following claims is TRUE?

-   A. Only abstract classes are available in Java, generic classes are not allowed.
-   B. A generic class is one that does not implement any of the methods in the class.
-   C. Generic classes are those whose declaration involves at least a type variable. For instance, public class Container&lt;T&gt;.
-   D. Generic classes are those that inherit from some superclass.

*   `Answer Key:C`

With regard to the following Java classes:
abstract class ArithmeticExp {
public abstract int eval();
}
class NumericExp extends ArithmeticExp {
private int n;
public int eval()
{ return n; }
}
which of the following claims is TRUE?

-   A. eval cannot be implemented in NumericExp because it is abstract in the superclass ArithmeticExp.
-   B. The implementation of eval in NumericExp can be used in all possible subclasses of ArithmeticExp.
-   C. The implementation of eval is available for the subclasses of NumericExp.
-   D. Abstract classes like ArithmeticExp cannot be defined in Java.

*   `Answer Key:C`

For a generic class A given by class A&lt;T&gt;{...}, which of the following declarations defines a generic class B extending A?

-   A. class B&lt;T&gt; implements A&lt;T&gt; {...}
-   B. class B&lt;T&gt; extends A&lt;T&gt;{...}
-   C. class B &lt;T extends A&gt; {...}
-   D. class B extends A&lt;Integer&gt;{...}

*   `Answer Key:B`

Indicate which of the following sentences on programming paradigms is TRUE:

-   A. The declarative paradigm includes functional, logic, and object-oriented.
-   B. All the paradigms are grouped in two categories: imperative and declarative.
-   C. Event-based programming is a paradigm based on interaction.
-   D. Each programming language belongs to one paradigm only.

*   `Answer Key:C`

Which of the following claims is WRONG?

-   A. A declarative program can be seen as an executable specification.
-   B. An imperative program describes a sequence of changes of state.
-   C. The logic paradigm is based on first-order logic.
-   D. Side-effects are a typical feature of functional languages.

*   `Answer Key:D`

The main function of the dispatcher in event-driven programming is:

-   A. determine the type of event and select the best handler.
-   B. manage the concurrency between two processes that handle the same event.
-   C. select the event to be considered by a handler that is currently running.
-   D. for every received event, run all the handles until one takes the event.

*   `Answer Key:A`

C++ performs call-by-value by default, but call-by-reference can be performed by adding the symbol & before the variable name. Indicate which is the result printed for variable A in the following C++ code:
void p(int &X, int Y) {
X=Y;
}
...
int A=1; int B=2;
p(A,A+B);
print A;

-   A. 1
-   B. 2
-   C. 3
-   D. 4

*   `Answer Key:C`

Reflection permits (mark the FALSE option):

-   A. To obtain and show, during the program execution, the name of all class instances that were created during the execution.
-   B. Reading a string from the keyboard and use such a string to create an object with this name.
-   C. To infer the axiomatic semantics of the language.
-   D. Reading a string from the keyboard and use it to call a method having this name.

*   `Answer Key:C`

Which kind of polymorphism is defined by the following Java code?
int myAdd(int x, int y, int z){ ... }
double myAdd(double x, double y, double z){ ... }

-   A. Inheritance.
-   B. Overloading.
-   C. Coercion.
-   D. Genericity.

*   `Answer Key:B`

Answer which option is TRUE:

-   A. An abstract class is a class that does not implement any of its methods.
-   B. A class can be defined as abstract, but it is not possible to declare a method as abstract.
-   C. An abstract class can only be instantiated if it inherits from a concrete class.
-   D. It is possible in Java that a class inherits from an abstract class and it is also abstract.

*   `Answer Key:D`

Consider the following classes
public class Instrument {
protected String name;
public Instrument (String n) {
name = n; }
public String getName() { return name; }
}
public class Wind extends Instrument{
protected String type;
public Viento (String n, String t) {
super (n);  
 type = t; }
public String getName() {
System.out.println("Name: " + super.getName()); }
}
Which of the following claims is TRUE?

-   A. Instrument is a (parametric) generic class.
-   B. Method getName in class Wind hides method getName in class Instrument.
-   C. Class Wind is a subclass of class Instrument.
-   D. Method getName in class Instrument overrides method getName in class Wind.

*   `Answer Key:C`

Which of the following claims about genericity in Java is WRONG?

-   A. Java permits the definition of generic classes.
-   B. Java permits the definition of generic methods.
-   C. Generic methods can be defined as part of a generic class only.
-   D. Generic classes may have several parameters.

*   `Answer Key:C`

For the following inheritance relationship:
public class Horse { ... };
public class Pony extends Horse { ... };
and the following lines of code:
Horse h = new Horse();
Pony p = h;
which of the following sentences is TRUE?

-   A. There is a compilation error.
-   B. Class Horse should be abstract.
-   C. The inheritance relationship is wrong: implements should be used instead of extends.
-   D. The code is compiled without problems.

*   `Answer Key:A`

In the functional paradigm

-   A. Recursion is not possible.
-   B. Data structures are not possible because there are no global variables.
-   C. There is no polymorphism, since there are not objects and classes.
-   D. There is no assignment instruction.

*   `Answer Key:D`

Indicate which of the following sentences about concurrent programming is FALSE:

-   A. Semaphores were introduced to synchronize concurrent processes.
-   B. Starvation happens when a process cannot access a resource due to its low priority.
-   C. Deadlock can happen only between three or more processes that access the same resources.
-   D. Data corruption can happen only when two programs write concurrently to the same resource.

*   `Answer Key:C`

Which of the following claims is TRUE?

-   A. Object-oriented programming languages (e.g., Java) do not support concurrent programming.
-   B. Concurrent programs consist of a main loop with two sections: event detection and event handling.
-   C. Imperative programs may give rise to side effects.
-   D. In declarative programming, program variables represent memory locations.

*   `Answer Key:C`

Select one of the combinations below so that each number in the figure is replaced by the appropriate kind of polymorphism:

-   polymorphism:

    -   ad-hoc:
        -   1
        -   2
    -   universal
        -   3
        -   4

-   A. 1: coercion
    2: inclusion (inheritance)
    3: overloading
    4: parametric (genericity)
-   B. 1: coercion
    2: overloading
    3: inclusion (inheritance)
    4: parametric (genericity)
-   C. 1: inclusion (inheritance)
    2: parametric (genericity)
    3: coercion
    4: overloading
-   D. 1: overloading
    2: parametric (genericity)
    3: inclusion (inheritance)
    4: coercion

*   `Answer Key:B`

Which of the following claims is TRUE?

-   A. In the call by reference parameter passing mechanism, runtime changes on the formal parameter do not change the initial data object
-   because a local copy is used.
-   B. The dynamic scope of a variable can be established in compilation time because it does not depend on the program execution.
-   C. A garbage collector can identify those objects that are not reachable (i.e., there is no active reference to them) and then remove them, thus releasing the corresponding memory space.
    D. Static memory management can allocate the amount of memory that will be necessary to execute a recursive function.

*   `Answer Key:C`

"... functions or operators that share a single name but can be applied to arguments of different types with different implementations depending on the type of the actual parameters."

-   A. Inheritance.
-   B. Overloading.
-   C. Genericity.
-   D. Abstraction.

*   `Answer Key:B`

Which of the following claims about genericity in Java is WRONG?

-   A. Java permits the definition of generic classes.
-   B. Java permits the definition of generic methods.
-   C. Generic methods can be defined as part of a generic class only.
-   D. Generic classes may have several parameters.

*   `Answer Key:C`

In the following fragment of Java code:
double myFun(int x, double y){
return x + y;
}
double myFun(double x, double y){
return x \* y;
}
which kind of polymorphism(s) can be found?

-   A. Overloading (only).
-   B. Coercion (only).
-   C. Overloading and genericity.
-   D. Overloading and coercion.

*   `Answer Key:D`

For a generic class A given by class A&lt;T&gt;{...}, which of the following declarations defines a generic class B extending A?

-   A. class B&lt;T&gt; implements A&lt;T&gt; {...}
-   B. class B&lt;T&gt; extends A&lt;T&gt;{...}
-   C. class B &lt;T extends A&gt; {...}
-   D. class B extends A&lt;Integer&gt;{...}

*   `Answer Key:B`

With regard to Java's generic classes, which of the following claims is TRUE?

-   A. Only abstract classes are available in Java, generic classes are not allowed.
-   B. A generic class is one that does not implement any of the methods in the class.
-   C. Generic classes are those whose declaration involves at least a type variable. For instance, public class Container&lt;T&gt;.
-   D. Generic classes are those that inherit from some superclass.

*   `Answer Key:C`

With regard to Parallel Programming, which of the following claims is TRUE?

-   A. In Parallel Programming we aim at accelerating algorithms by distributing both data and the execution workload among different processors.
-   B. Deadlocks were brought by Parallel Programming due to several processes trying to gain access to the same resource; they are then enqueued under some priority-based policy so that the least prioritary process never gets access to the requested resource.
-   C. Starvation is a problem of Parallel Programming where two programs block any access to a shared resource.
-   D. In Parallel Programming threads (processes) are required; thus, each object has an associated locking mechanism, just in case it is required for use by more than one thread.

*   `Answer Key:A`

Which of the following claims is TRUE of a declarative programming language?

-   A. Programs can be viewed as executable specifications.
-   B. A program is a sequence of instructions to control the machine that runs the program.
-   C. An essential element is the while loop.
-   D. We can give rise to the so-called side effects by means of the assignment instruction.

*   `Answer Key:A`

Which of the following claims about the Object-Oriented (OO) Paradigm is TRUE?

-   A. Its essential elements are: encapsulation, modularity, abstraction, and hierarchy.
-   B. No OO language is concurrent.
-   C. Only OO languages can be used to handle events.
-   D. Only the imperative languages can be Object Oriented.

*   `Answer Key:A`

Indicate which of the following sentences is TRUE:

-    A. Polymorphism is exclusive of imperative languages.
-    B. The parameter of a generic class in Java takes values in the domain of data.
-    C. Universal and inclusion polymorphism cannot be used together in the same programming language because it is not possible to keep type compatibility for type variables.
-    D. A generic function or a generic class define a structure that it is common to a potentially infinite number of types.

* A

With regard to the following Java classes:

```js
abstract class ArithmeticExp {
  public abstract int eval();
}

class NumericExp extends ArithmeticExp {
  private int n;
  public int eval()
    { return n; }
}
```

which of the following claims is TRUE?

-    A.  eval cannot be implemented in NumericExp because it is abstract in the superclass ArithmeticExp.
-    B.  The implementation of eval in NumericExp can be used in all possible subclasses of ArithmeticExp.
-    C.   The implementation of eval is available for the subclasses of NumericExp.
-    D.  Abstract classes like ArithmeticExp cannot be defined in Java.

* C

 Indicate which is the result obtained by the following Java code:
 
```js
class Animal{
     public void move(){
          System.out.println("Animals can move");
     }
}
class Dog extends Animal{
     public void move(){
          System.out.println("Dogs can walk and run");
     }
}
public class Test{
     public static void main(String args[]){
          Animal a = new Animal();
          Animal b = new Dog();
          a.move();
          b.move();
     }
}
```

- A.
Animals can move
Animals can move

 
- B.
Dogs can walk and run
Dogs can walk and run

 
- C.
Animals can move
Dogs can walk and run

 
- D. None, since  `Animal b = new Dog();` produces an error. 

* C