2: Quizzes Flashcards
Which of the following is NOT a Java relational operator?
=
>=
!=
>
=
Which of the following is true?
- When using == to compare reference variables, you are testing for “identity equality” – that the two variables refer to the same object.
- The .equals() method tests for “content equality” – that the objects are considered equivalent to each other.
1 and 2 are both true.
Which of the following operators may NOT be used with operands of type boolean?
&&
||
!=
!
All of these may be used with type boolean.
What is a common use for a variable of type boolean?
Flag variable
What is a common name for a method that returns type boolean?
Predicate method
What are the valid data types for a switch statement.
int, char, String
If a break statement is not included at the end of each action (alternative) in a switch instruction, what is the result?
More than one action may be executed.
You are writing a program that will allow a user to enter a single word identifying her ‘sign’ in the Chinese zodiac (e.g. “Dog”) and then show some information about that sign. Obviously a decision must be made in this program. Which selection structure(s) could you use that will compile?
Either if statements or a switch statement could be used.
Which of the following is true in Java?
- Every else must have a preceding if.
- Every if must have a following else.
1 is true.
What kind of loop is a data validation loop?
An indefinite loop.
Which loop control structure can NOT be used if there are conditions under which the body of the loop should be executed zero times?
do…while
You know that a for loop is usually the best choice for a counting loop, but which other loop control structure(s) could possibly be used to create a counting loop?
Any of the loop control structures can be used to create a counting loop.
How are the following implemented?
- The state of an object.
- The behavior of an object.
- Through instance variables.
2. Through instance methods.
Another term for instance variable is…?
Field.
What is the keyword for the implicit parameter?
this
A method that changes the state of an object is known as….
a mutator.
A method that provides information about the state of an object is known as…
an accessor.
A piece of code that initializes the state of an object is known as…
a constructor.
What is the keyword used to encapsulate the fields of an object?
private
An object’s properties are also known as what?
Instance variables