Quiz5_43key

advertisement
COP 2551_43
Chapter 5 Quiz
Name ______________________________________
6/24/2004
For multiple choice questions, circle the letter beside the best answer.
1.
Given the following instantiations and assignment statement:
ChessPiece bishop1 = new ChessPiece();
ChessPiece bishop2 = new ChessPiece();
bishop2 = bishop1;
Which of the following statements is/are then true?
a.
b.
c.
d.
2.
Which of the following code segments will check to see that the name variable
actually points to an object before trying to display the length of the String that is
stored in name?
a.
b.
c.
d
3.
bishop1 and bishop2 now contain the address of the same ChessPiece object.
bishop1 and bishop2 are now aliases for different ChessPiece objects.
both bishop1 and bishop2 contain the address of garbage ChessPiece objects.
all of the above statements are true.
if (name != empty)
System.out.println(name.length());
if (name != null)
System.out.println(name.length());
if (name != blank)
System.out.println(name.length());
Any of the above will perform the desired check..
Which of the following statements is true of actual and formal parameters?
a.
b.
c.
d.
If an actual parameter of a primitive type (int, float, etc.) is passed to a method
and the formal parameter in the called method changes the value that was
passed, the value will also be changed in the calling method.
If an actual parameter of a object type is passed to a method and the
corresponding formal parameter in the called method instantiates a new object
of the same type that was passed and changes a value in the new object, the
value will also be changed in the calling method.
If an actual parameter of an object type is passed to a method and the formal
parameter in the called method changes a value in the object that was passed,
the value will also be changed in the calling method.
All of the above statements are true.
4.
In Java, the word this
a.
b.
c.
d.
5.
Static methods
a.
b.
c.
d.
6.
constants
abstract methods
implemented methods
only a. and b. above
a., b. and c. above
A class that implements an interface
a.
b.
c.
d.
9.
A nested class is declared inside another class.
A nested class produces a separate bytecode file.
A nonstatic nested class is called an inner class.
All of the above are true for nested classes.
A Java interface is a collection of
a.
b.
c.
d.
e.
8.
can reference instance variables, but not static variables.
cannot reference local variables.
are also referred to as class methods.
are also referred to as instance methods.
Which of the following is/are true of nested classes?
a.
b.
c.
d.
7.
is a reserved word.
allows an object to refer to itself.
refers to the object through which a method was invoked.
all of the above are true of the word this.
can choose to either implement or not implement any specific method that is
part of the interface.
is not allowed to implement any methods that are not part of the interface.
must implement all methods in the interface.
must comply with both a and b. above.
When a class implements more than one interface, the implements clause
a.
b.
c.
d.
only needs to name the first interface.
must provide the names of all the interfaces separated by commas.
must provide the names of all the interfaces separated by semicolons.
A class cannot implement more than one interface.
10.
Which of the following is/are true of classes and interfaces?
a.
b.
c.
d.
In general, an object of one class cannot be assigned to a reference variable of
another class.
An interface reference variable can be used to refer to any object of any class
that implements the interface.
The interface construct serves as the basis for a programming technique
known as polymorphism.
All of the above are true for classes and interfaces.
NOTE: I decided not to count question #10 for reasons I'll explain in class (Basically, it
wasn't covered adequately in class or the text).
5 Point Bonus
Write the header line for a class named Dog that is a public class which implements an
interface named Speaker.
public class Dog implements Speaker
Download