COP3804 Quiz terms (multiple choice, true and false, fill in the blank)
What is the term for the relationship created by object aggregation?
"Has a"
What is an object in Java?
An instance of a class that encapsulates data and behavior.
The JVM periodically performs the ______ process to remove unreferenced objects from memory.
garbage collection
An exception's default error message can be retrieved by using the ______ method.
getMessage()
What tells the Java compiler that a method is meant to override a method in the superclass?
@Override
What is method overloading in Java?
A feature that allows a class to have multiple methods with the same name but different parameter lists.
Which of the following statements is true about arrays and ArrayLists in Java?
An array is a fixed data structure, while an ArrayList is a dynamic size data structure.
What is an example of a superclass-subclass relationship?
Circle extends Shape
All of the exceptions you will handle are instances of classes that extend the ______ class.
Exception
True/False. A subclass can have multiple superclasses.
False
True/False. An instance of a class have to exist in order for values to be stored in a class's static fields.
False
True/False. If two methods in the same class have the same name but different signatures, the second overrides the first.
False
True/False. In an inheritance relationship, the subclass constructor always executes before the superclass constructor.
False
True/False. Private members (fields and methods) in a superclass are directly accessible by a subclass.
False
True/False. The key word "this" is the name of a reference variable that is available to all static methods.
False
True/False. The throw statement informs the compiler that a method throws one or more exceptions.
False
True/false. A catch clause that uses a parameter variable of the Exception type is capable of catching any exception that extends the Error class.
False
In Java, what is the purpose of the "new" keyboard?
It creates a new instance of a class and returns a reference to it.
Which access modifier allows a class or member to be accessible only within the same package?
Protected
What happens if a program does not handle an unchecked exception?
The program is halted and the default exception handler handles the exception.
In an inheritance relationship ________
The superclass constructor always executes before the subclass constructor.
What is the primary purpose of the "constructor" in a Java class?
To create new instances of the class.
True/False. A single copy of a class's static field is shared by all instances of the class.
True
True/False. Because every class directly or indirectly inherits from the Object class, every class inherits the Object class's members.
True
True/False. Every class has a toString method and an equals method inherited from the Object class.
True
True/False. If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent: System.out.println(object1); System.out.println(object1.toString());
True
True/False. It is not possible for a superclass to call a subclass's method.
True
True/False. The call stack is an internal list of all the methods that are currently executing.
True
True/False. When an object is serialized, it is converted into a series of bytes that contain the object's data.
True
True/False. When you deserialize an object using the readObject method, you must cast the return value to the desired class type.
True
True/False. You can write a super statement that calls a superclass constructor but only in the subclass's constructor.
True
Which keyword is used to establish an inheritance relationship between two classes in Java?
extends
The try statement may have an optional ______ clause which must appear after all of the catch clauses.
finally
When you write a method that throws a checked exception, you must ________.
have a throws clause in the method header.
What type of relationship exists between two objects when one object is a specialized version of another object?
is a
A deep copy of an object _________ .
is an operation that copies an aggregate object and all the objects that it references.
When the this variable is used to call a constructor _______.
it must be the first statement in the constructor making the call.
Enumerated types have the ______ method which returns the position of an enum constant in the declaration list.
ordinal
Which of the following statements declares Salaried as a subclass of PayType?
public class Salaried extends PayType
Static methods can only operate on _____ fields.
static