I. Examine the following statements and indicate whether it is true or false:
-
All methods in an abstract superclass must be declared abstract.
Chapter 3.3 -
A class declared final cannot be subclassed. Every method of a final class is implicitly final.
-
A redefinition of a superclass method in a subclass need not have the same signature as the superclass method. Such a redefinition is not method overriding but is simply an example of method overloading.
Chapter 2 -
A constructor is a special method with the same name as the class that is used to initialize the members of a class object. Constructors are called when objects of their classes are instantiated.
-
A method declared static cannot access nonstatic class members. A static method has not this reference because static class variables and static methods exist independent of any objects of a class.
-
An array subscript may be an integer or an integer expression. If a program uses an expression as a subscript, then the expression is evaluated to determine the particular element of the array.
Chapter 2.2 -
To pass one row of a double-subscripted array to a method that receives a single-subscripted array, simply pass the name of the array followed by the row subscript.
Chapter 2.2 -
Overloaded methods can have different return values, and must have different parameter lists. Two methods differing only by return type will result in a compilation error.
Chapter 2 -
The applet’s paint method is called after the init method completes execution and the start method has started executing to draw on the applet. It is also called automatically every time the applet needs to be repainted.
Chapter 9 -
Any block of Java code may contain variable declarations.
II. Multiple choice. There’s only one correct choice for each problem.
- Given:
public class AnimalHouse {
private E animal;
public void setAnimal(E x) {
animal = x;
}
public E getAnimal() {
return animal;
}
}
public class Animal{}
public class Cat extends Animal {}
public class Dog extends Animal {}
Which statement below compiles?
A.AnimalHouse house = new AnimalHouse();
B.AnimalHouse house = new AnimalHouse();
C.AnimalHouse<?> house = new AnimalHouse(); house.setAnimal(new Cat());
D.AnimalHouse house = new AnimalHouse(); house.setAnimal(new Dog());
Chapter 4.2