Chapter 6

25 July 2022
4.7 (114 reviews)
37 test answers

Unlock all answers in this set

Unlock answers (33)
question
When you write an enumerated type declaration, you are actually creating a special kind of class. do not enclose the enum constants in quotation marks. should use the standard convention of writing the enum constants in uppercase. All of these
answer
All of These
question
The only limitation that static methods have is they must be declared outside of the class. they cannot refer to nonstatic members of the class. they can only be called from static members of the class. they can refer to only nonstatic members of the class.
answer
they cannot refer to nonstatic members of the class.
question
When an object is passed as an argument, it is actually a reference to the object that is passed. True False
answer
True
question
You can use the enum key word to create your own data type. specify the values that belong to that type. Both create your own data type and specify the values that belong to that type Neither create your own data type nor specify the values that belong to that type
answer
Both create your own data type and specify the values that belong to that type
question
Look at the following declaration: enum Tree( OAK, MAPLE, PINE) (?)(?) What is the fully-qualified name of the PINE enum constant? enum.PINE PINE Tree.PINE enum.Tree.PINE
answer
Tree.PINE
question
When the this variable is used to call a constructor it must be the first statement in the constructor making the call. it can be anywhere in the constructor making the call. it must be the last statement in the constructor making the call. You cannot use the this variable in a constructor call.
answer
it must be the first statement in the constructor making the call.
question
A method's signature consists of the method name and the parameter list. the return type, the method name, and the parameter list. the size of the method in memory. the return type and the method name.
answer
the return type, the method name, and the parameter list. WRONG the method name and the parameter list.
question
Enumerated types have this method, which returns the position of an enum constant in the declaration list. position location ordinal index
answer
ordinal
question
An enumerated data type is actually a special type of class. True False
answer
True
question
A class that is defined inside of another class is called a(n) nested class. enumerated class. inner class. helper class.
answer
inner class.
question
The key word this is the name of a reference variable that an object can use to refer to itself. True False
answer
True
question
enum constants have a toString method. True False
answer
True
question
If you write a toString method for a class, Java will automatically call the method any time you concatenate an object of the class with a string. True False
answer
True
question
Overloading is writing a method that does too much processing. writing a program that is too large to fit in memory. having two or more methods with the same name, but different signatures. having two or more methods with the same signature.
answer
having two or more methods with the same name, but different signatures.
question
You can declare an enumerated data type inside of a method. True False
answer
False
question
________ is the term for the relationship created by object aggregation. "Has a" Inner class "Is a" One-to-many
answer
"Has a"
question
You cannot use the fully-qualified name of an enum constant for a case expression. an argument to a method. a boolean expression. All of these
answer
a case expression.
question
When a method in the ________ class returns a reference to a field object, it should return a reference to a copy of the field object to prevent "security holes." aggregate inner String nested
answer
aggregate
question
If you have defined a class SavingsAccount with a public static method getNumberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will call the getNumberOfAccounts method? account20.getNumberOfAccounts(); SavingsAccount.getNumberOfAccounts(); getNumberOfAccounts(); None of these
answer
getNumberOfAccounts(); WRONG account20.getNumberOfAccounts(); WRONG
question
If object1 and object2 are objects of the same class, to make object2 a copy of object1 write a method for the class that will make a field by field copy of object1 data members into object2 data members. use the copy method that is a part of the Java API. use the default constructor to create object2 with object1 data members. use an assignment statement to make object2 a copy of object1.
answer
write a method for the class that will make a field by field copy of object1 data members into object2 data members.
question
Assuming the following declaration exists: enum Tree( OAK, MAPLE, PINE) what will the following code display OAK Tree.OAK 0 1
answer
OAK
question
The "has a" relationship is sometimes called a(n) ________ because one object is part of a greater whole. enterprise possession mutual relationship whole-part relationship
answer
whole-part relationship
question
Assume the class BankAccount has been created, and the following statement correctly creates an instance of the class: BankAccount account = new BankAccount(5000.0); What is true about the following statement? System.out.println(account); A runtime error will occur. The method will display unreadable binary data on the screen. The account object's toString method will be implicitly called. A compiler error will occur.
answer
The account object's toString method will be implicitly called.
question
When you make a copy of the aggregate object and of the objects it references, you are performing a shallow copy. you are performing a nested copy. you are performing a deep copy. a compiler error will occur.
answer
you are performing a nested copy. WRONG(?)
question
To get the name of a calling enum constant, simply use the enum constant in the statement. use the ordinal method. use the displayName method. use the toString method.
answer
use the toString method.
question
A class's static methods do not operate on the fields that belong to any instance of the class. True False
answer
True
question
If a class has a method named finalize, it is called automatically just before an instance of the class is destroyed by the garbage collector. True False
answer
True
question
A static field is created by placing the key word static after the access specifier and field's data type. after the access specifier and before the field's data type. after the field name. in brackets, before the field's data type.
answer
after the access specifier and before the field's data type.
question
An instance of a class does not have to exist in order for values to be stored in a class's static fields. True False
answer
True
question
A declaration for an enumerated type begins with this key word. enumerated enum type ENUM enum
answer
enum
question
You may use this to compare two enum data values. the ordinal method the ==, >, and < operators the equals and compareTo methods the moreThan, lessThan, and equalsTo methods
answer
the equals and compareTo methods
question
Of the following, which would be considered the no-arg constructor for the Rectangle class? public Rectangle(int len, int width) public Rectangle(double len, double width) public Rectangle() All of these
answer
All of these WRONG
question
By default, a reference variable that is an instance field is initialized to the value null. 0. void. static.
answer
null.
question
If the following is from the method section of a UML diagram, which of the following statements is true? + equals (object2:Stock) : boolean This is a public method that accepts a Stock object as its argument and returns a boolean value. This is a public method that returns a reference to a String object. This is a private method that receives two objects from the Stock class and returns a boolean value. This is a private method that returns a boolean value.
answer
This is a public method that accepts a Stock object as its argument and returns a boolean value.
question
When a field is declared static, there will be a copy of the field for each method in the class. a copy of the field in each class object. only one copy of the field in memory. two reference copies of the field for each method in the class.
answer
only one copy of the field in memory.
question
When a method's return type is an object, what is actually returned to the calling program? a reference to an object of that class only the values in the object that the method accessed an object of that class a null reference
answer
a reference to an object of that class
question
The names of the enum constants in an enumerated data type must be enclosed in quotation marks. True False
answer
False