Deck 1: Object-Oriented Programming and Class Hierarchies
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/41
Play
Full screen (f)
Deck 1: Object-Oriented Programming and Class Hierarchies
1
Each class that implements an interface must provide the complete definition of all methods declared in the interface.
True
2
One way to make code reusable is to ____________________ or combine data elements together with methods that operate on that data in a separate program module.
encapsulate
3
The combination of data together with its methods is called a(n) ____________________ data type.
abstract
4
A Java ____________________ specifies the names, parameters, and return values of the ADT methods without specifying how the methods perform their operations or how the data is internally represented.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
5
Method descriptions in an interface are called method ____________________.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
6
The Javadoc program for Java documentation focuses on text that is enclosed with the delimeters ____________________.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
7
A(n) ____ is a model of a physical entity or activity.
A) abstraction
B) interface
C) contract
D) use case
A) abstraction
B) interface
C) contract
D) use case
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
8
A Java interface is a(n) ____ between the interface designer and the programmer who codes a class that implements the interface.
A) precondition
B) postcondition
C) message
D) contract
A) precondition
B) postcondition
C) message
D) contract
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
9
A major reason for the popularity of object-oriented programming is that it enables programmers to reuse previously written code saved as classes.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
10
An object that is a RuntimeException is an Exception. The converse is also true.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
11
The has-a relationship between classes means that one class is a subclass of the other.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
12
The is-a relationship between classes means that one class has the second class as an attribute.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
13
The superclass of all Java classes is ____________________.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
14
The ____________________ call in a class constructor invokes the superclass's constructor that has the corresponding argumentList.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
15
Java automatically applies the ____________________ method to an object referenced in a String expression.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
16
Having multiple methods with the same name but different signatures in a class is called ____________________.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
17
A(n) ____________________ class is used to store a primitive-type value in an object type.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
18
You should always override the ____________________ method if you want to represent an object's state.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
19
In UML class diagrams, the ____ sign next to the method names indicate that the methods are public.
A) @
B) *
C) +
D) -
A) @
B) *
C) +
D) -
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
20
If no constructors are defined for a class, the ____ constructor for that class will be provided by default.
A) private
B) super
C) public
D) no-parameter
A) private
B) super
C) public
D) no-parameter
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
21
A data field (or method) with ____ visibility can be accessed in either the class defining it, in any subclass of that class, or any class in the same package.
A) private
B) protected
C) public
D) instanceof
A) private
B) protected
C) public
D) instanceof
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
22
The call to ____ invokes the constructor for the current class whose parameter list matches the argument list.
A) super()
B) super
C) this()
D) abstract
A) super()
B) super
C) this()
D) abstract
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following statements is correct?
A) is-a and has-a relationships cannot be combined.
B) An abstract class can be instantiated.
C) An abstract class cannot declare abstract methods.
D) In Java, a variable of a superclass type can reference an object of a subclass type.
A) is-a and has-a relationships cannot be combined.
B) An abstract class can be instantiated.
C) An abstract class cannot declare abstract methods.
D) In Java, a variable of a superclass type can reference an object of a subclass type.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following statements is correct?
A) Interfaces can define instance variables and methods.
B) Abstract classes can define constants.
C) Interfaces can extend another class.
D) Instances of abstract classes can be created.
A) Interfaces can define instance variables and methods.
B) Abstract classes can define constants.
C) Interfaces can extend another class.
D) Instances of abstract classes can be created.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
25
Which of the following methods of java.lang.Object compares an object to its argument?
A) boolean equals(Object obj)
B) int hashCode()
C) Object clone()
D) String toString()
A) boolean equals(Object obj)
B) int hashCode()
C) Object clone()
D) String toString()
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
26
The nextInt method will throw a(n) if an integer choice is
not entered.
not entered.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
27
ArrayIndexOutOfBoundsException is thrown by the JVM when an index value used to access an element in an array is less than zero or greater than or equal to the array's length.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
28
A ____________________ is thrown when the token returned by a Scanner next... method does not match the pattern for the expected data type.
A) ArithmeticException
B) IllegalArgumentException
C) InputMismatchException
D) NumberFormatException
A) ArithmeticException
B) IllegalArgumentException
C) InputMismatchException
D) NumberFormatException
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
29
____________________ errors are mistakes in your use of the grammar of the Java language.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
30
____________________ errors occur during program execution .
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
31
The ____________________ is thrown when a program attempts to convert a non-numeric string to a numeric value.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
32
The class ____________________ is the superclass of all exceptions.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
33
Which of the following would cause an ArrayIndexOutOfBounds error?
A) public boolean setElementOfX(int index, int val) {
if(index >= 0 && index < x.length) {
x[index] = val;
return true;
} else {
return false;
}
}
B) public static void main(Strin[] args) {
String inputFileName;
if (args.length > 0)
inputFileName = args[0];
else
inputFileName = "Phone.dat";
}
C) for (int i = 0; i
x[i] = i + i;
D) for (int i = 0; i <= x.length; i++)
x[i] = i * i;
A) public boolean setElementOfX(int index, int val) {
if(index >= 0 && index < x.length) {
x[index] = val;
return true;
} else {
return false;
}
}
B) public static void main(Strin[] args) {
String inputFileName;
if (args.length > 0)
inputFileName = args[0];
else
inputFileName = "Phone.dat";
}
C) for (int i = 0; i
x[i] = i + i;
D) for (int i = 0; i <= x.length; i++)
x[i] = i * i;
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
34
A(n) ____ is an error that is normally not due to programmer error and is beyond the control of the programmer.
A) checked exception
B) bug
C) syntax error
D) unchecked exception
A) checked exception
B) bug
C) syntax error
D) unchecked exception
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following statements is correct?
A) If a checked exception is likely to be caught in a higher-level method, declare that it can occur using a catch clause.
B) If an exception is recoverable in the current method, handle the exception in the current method.
C) If an unchecked exception is is likely to be caught in a higher-level method, use a @catch tag to document this fact in the Javadoc comment for the method.
D) If an unchecked exception is likely to be caught in a higher-level method, declare that it can occur using a throws clause.
A) If a checked exception is likely to be caught in a higher-level method, declare that it can occur using a catch clause.
B) If an exception is recoverable in the current method, handle the exception in the current method.
C) If an unchecked exception is is likely to be caught in a higher-level method, use a @catch tag to document this fact in the Javadoc comment for the method.
D) If an unchecked exception is likely to be caught in a higher-level method, declare that it can occur using a throws clause.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
36
The ____ represent error conditions that may occur as a result of programmer error or as a result of serious external conditions that are considered unrecoverable.
A) unchecked exceptions
B) run-time error
C) checked exceptions
D) exception
A) unchecked exceptions
B) run-time error
C) checked exceptions
D) exception
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
37
Exception classes that are subclasses of ____ are unchecked.
A) EOFException
B) FileNotFoundException
C) IOException
D) RuntimeException
A) EOFException
B) FileNotFoundException
C) IOException
D) RuntimeException
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
38
Which of the following is a RuntimeException?
A) AssertionErorr
B) FileNotFoundException
C) IllegalArgumentException
D) UnknownError
A) AssertionErorr
B) FileNotFoundException
C) IllegalArgumentException
D) UnknownError
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
39
Classes that are not part of a package may access only ________________ members of classes in the package.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
40
____________________ visibility is for members of a class that should not be accessible to anyone but the class, not even classes that extend it.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
41
Which of the following is considered a visibility modifier in Java?
A) private
B) Inherit
C) Superclass
D) String
A) private
B) Inherit
C) Superclass
D) String
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck