Deck 6: A Second Look at Classes and Objects

Full screen (f)
exit full mode
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) A runtime error will occur.
B) The method will display unreadable binary data on the screen.
C) The account object's toString method will be implicitly called.
D) A compiler error will occur.
Use Space or
up arrow
down arrow
to flip the card.
Question
Of the following, which would be considered the no-arg constructor for the Rectangle class?

A) public Rectangle(int len, int width)
B) public Rectangle(double len, double width)
C) public Rectangle()
D) All of the above
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?

A) account20.getNumberOfAccounts();
B) SavingsAccount.getNumberOfAccounts();
C) getNumberOfAccounts();
D) None of the above
Question
Overloading is

A) writing a method that does too much processing.
B) writing a program that is too large to fit in memory.
C) having two or more methods with the same name, but different signatures.
D) having two or more methods with the same signature.
Question
When the this variable is used to call a constructor

A) it must be the first statement in the constructor making the call.
B) it can be anywhere in the constructor making the call.
C) it must be the last statement in the constructor making the call.
D) You cannot use the this variable in a constructor call.
Question
Assuming the following declaration exists:
Enum Tree { OAK, MAPLE, PINE }
What will the following code display?
System.out.println(Tree.OAK);

A) OAK
B) Tree.OAK
C) 0
D) 1
Question
Enumerated types have this method, which returns the position of an enum constant in the declaration list.

A) position
B) location
C) ordinal
D) index
Question
The "has a" relationship is sometimes called a(n) ________ because one object is part of a greater whole.

A) enterprise
B) possession
C) mutual relationship
D) whole-part relationship
Question
By default, a reference variable that is an instance field is initialized to the value

A) null.
B) 0.
C) void.
D) static.
Question
A method's signature consists of

A) the method name and the parameter list.
B) the return type, the method name, and the parameter list.
C) the size of the method in memory.
D) the return type and the method name.
Question
When you write an enumerated type declaration, you

A) are actually creating a special kind of class.
B) do not enclose the enum constants in quotation marks.
C) should use the standard convention of writing the enum constants in uppercase.
D) All of the above
Question
A class that is defined inside of another class is called a(n)

A) nested class.
B) enumerated class.
C) inner class.
D) helper class.
Question
You cannot use the fully-qualified name of an enum constant for

A) a case expression.
B) an argument to a method.
C) a boolean expression.
D) All of the above
Question
If the following is from the method section of a UML diagram, which of the following statements is true?
+ equals(object2:Stock) : boolean

A) This is a public method that accepts a Stock object as its argument and returns a boolean value.
B) This is a public method that returns a reference to a String object.
C) This is a private method that receives two objects from the Stock class and returns a boolean value.
D) This is a private method that returns a boolean value.
Question
When you make a copy of the aggregate object and of the objects it references,

A) you are performing a shallow copy.
B) you are performing a nested copy.
C) you are performing a deep copy.
D) a compiler error will occur.
Question
________ is the term for the relationship created by object aggregation.

A) "Has a"
B) Inner class
C) "Is a"
D) One-to-many
Question
If object1 and object2 are objects of the same class, to make object2 a copy of object1

A) write a method for the class that will make a field by field copy of object1 data members into object2 data members.
B) use the copy method that is a part of the Java API.
C) use the default constructor to create object2 with object1 data members.
D) use an assignment statement to make object2 a copy of object1.
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."

A) aggregate
B) inner
C) String
D) nested
Question
The only limitation that static methods have is

A) they must be declared outside of the class.
B) they cannot refer to nonstatic members of the class.
C) they can only be called from static members of the class.
D) they can refer to only nonstatic members of the class.
Question
When a method's return type is an object, what is actually returned to the calling program?

A) a reference to an object of that class
B) only the values in the object that the method accessed
C) an object of that class
D) a null reference
Question
The names of the enum constants in an enumerated data type must be enclosed in quotation marks.
Question
CRC stands for

A) Class, Recyclability, Collaborations.
B) Class, Redundancy, Collections.
C) Class, Responsibilities, Collaborations.
D) Code, Reuse, Constancy.
Question
Look at the following declaration:
Enum Tree { OAK, MAPLE, PINE }
What is the fully-qualified name of the PINE enum constant?

A) enum.PINE
B) PINE
C) Tree.PINE
D) enum.Tree.PINE
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.
Question
A declaration for an enumerated type begins with this key word.

A) enumerated
B) enum type
C) ENUM
D) enum
Question
What will be returned from the method, if the following is the method header?
Public Rectangle getRectangle()

A) the address of an object of the Rectangle class
B) the values stored in the data members of the Rectangle object
C) a null value
D) an object that is contained in the class Rectangle
Question
When an object is passed as an argument, it is actually a reference to the object that is passed.
Question
An enumerated data type is actually a special type of class.
Question
You may use this to compare two enum data values.

A) the ordinal method
B) the ==, >, and < operators
C) the equals and compareTo methods
D) the moreThan, lessThan, and equalsTo methods
Question
enum constants have a toString method.
Question
The key word this is the name of a reference variable that an object can use to refer to itself.
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.
Question
The JVM periodically performs this process to remove unreferenced objects from memory.

A) memory shuffling
B) system restore
C) garbage collection
D) memory sweeping
Question
You can use the enum key word to

A) create your own data type.
B) specify the values that belong to that type.
C) Both A and B
D) Neither A nor B
Question
An instance of a class does not have to exist in order for values to be stored in a class's static fields.
Question
You can declare an enumerated data type inside of a method.
Question
A class's static methods do not operate on the fields that belong to any instance of the class.
Question
When a field is declared static, there will be

A) a copy of the field for each method in the class.
B) a copy of the field in each class object.
C) only one copy of the field in memory.
D) two reference copies of the field for each method in the class.
Question
A static field is created by placing the key word static

A) after the access specifier and field's data type.
B) after the access specifier and before the field's data type.
C) after the field name.
D) in brackets, before the field's data type.
Question
To get the name of a calling enum constant,

A) simply use the enum constant in the statement.
B) use the ordinal method.
C) use the displayName method.
D) use the toString method.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 6: A Second Look at Classes and Objects
1
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) A runtime error will occur.
B) The method will display unreadable binary data on the screen.
C) The account object's toString method will be implicitly called.
D) A compiler error will occur.
C
2
Of the following, which would be considered the no-arg constructor for the Rectangle class?

A) public Rectangle(int len, int width)
B) public Rectangle(double len, double width)
C) public Rectangle()
D) All of the above
C
3
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?

A) account20.getNumberOfAccounts();
B) SavingsAccount.getNumberOfAccounts();
C) getNumberOfAccounts();
D) None of the above
B
4
Overloading is

A) writing a method that does too much processing.
B) writing a program that is too large to fit in memory.
C) having two or more methods with the same name, but different signatures.
D) having two or more methods with the same signature.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
When the this variable is used to call a constructor

A) it must be the first statement in the constructor making the call.
B) it can be anywhere in the constructor making the call.
C) it must be the last statement in the constructor making the call.
D) You cannot use the this variable in a constructor call.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
Assuming the following declaration exists:
Enum Tree { OAK, MAPLE, PINE }
What will the following code display?
System.out.println(Tree.OAK);

A) OAK
B) Tree.OAK
C) 0
D) 1
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
Enumerated types have this method, which returns the position of an enum constant in the declaration list.

A) position
B) location
C) ordinal
D) index
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
The "has a" relationship is sometimes called a(n) ________ because one object is part of a greater whole.

A) enterprise
B) possession
C) mutual relationship
D) whole-part relationship
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
By default, a reference variable that is an instance field is initialized to the value

A) null.
B) 0.
C) void.
D) static.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
A method's signature consists of

A) the method name and the parameter list.
B) the return type, the method name, and the parameter list.
C) the size of the method in memory.
D) the return type and the method name.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
When you write an enumerated type declaration, you

A) are actually creating a special kind of class.
B) do not enclose the enum constants in quotation marks.
C) should use the standard convention of writing the enum constants in uppercase.
D) All of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
A class that is defined inside of another class is called a(n)

A) nested class.
B) enumerated class.
C) inner class.
D) helper class.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
You cannot use the fully-qualified name of an enum constant for

A) a case expression.
B) an argument to a method.
C) a boolean expression.
D) All of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
If the following is from the method section of a UML diagram, which of the following statements is true?
+ equals(object2:Stock) : boolean

A) This is a public method that accepts a Stock object as its argument and returns a boolean value.
B) This is a public method that returns a reference to a String object.
C) This is a private method that receives two objects from the Stock class and returns a boolean value.
D) This is a private method that returns a boolean value.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
When you make a copy of the aggregate object and of the objects it references,

A) you are performing a shallow copy.
B) you are performing a nested copy.
C) you are performing a deep copy.
D) a compiler error will occur.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
________ is the term for the relationship created by object aggregation.

A) "Has a"
B) Inner class
C) "Is a"
D) One-to-many
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
If object1 and object2 are objects of the same class, to make object2 a copy of object1

A) write a method for the class that will make a field by field copy of object1 data members into object2 data members.
B) use the copy method that is a part of the Java API.
C) use the default constructor to create object2 with object1 data members.
D) use an assignment statement to make object2 a copy of object1.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
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."

A) aggregate
B) inner
C) String
D) nested
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
The only limitation that static methods have is

A) they must be declared outside of the class.
B) they cannot refer to nonstatic members of the class.
C) they can only be called from static members of the class.
D) they can refer to only nonstatic members of the class.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
When a method's return type is an object, what is actually returned to the calling program?

A) a reference to an object of that class
B) only the values in the object that the method accessed
C) an object of that class
D) a null reference
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
The names of the enum constants in an enumerated data type must be enclosed in quotation marks.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
CRC stands for

A) Class, Recyclability, Collaborations.
B) Class, Redundancy, Collections.
C) Class, Responsibilities, Collaborations.
D) Code, Reuse, Constancy.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
Look at the following declaration:
Enum Tree { OAK, MAPLE, PINE }
What is the fully-qualified name of the PINE enum constant?

A) enum.PINE
B) PINE
C) Tree.PINE
D) enum.Tree.PINE
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
A declaration for an enumerated type begins with this key word.

A) enumerated
B) enum type
C) ENUM
D) enum
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
What will be returned from the method, if the following is the method header?
Public Rectangle getRectangle()

A) the address of an object of the Rectangle class
B) the values stored in the data members of the Rectangle object
C) a null value
D) an object that is contained in the class Rectangle
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
When an object is passed as an argument, it is actually a reference to the object that is passed.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
An enumerated data type is actually a special type of class.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
You may use this to compare two enum data values.

A) the ordinal method
B) the ==, >, and < operators
C) the equals and compareTo methods
D) the moreThan, lessThan, and equalsTo methods
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
enum constants have a toString method.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
The key word this is the name of a reference variable that an object can use to refer to itself.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
The JVM periodically performs this process to remove unreferenced objects from memory.

A) memory shuffling
B) system restore
C) garbage collection
D) memory sweeping
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
You can use the enum key word to

A) create your own data type.
B) specify the values that belong to that type.
C) Both A and B
D) Neither A nor B
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
An instance of a class does not have to exist in order for values to be stored in a class's static fields.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
You can declare an enumerated data type inside of a method.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
A class's static methods do not operate on the fields that belong to any instance of the class.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
When a field is declared static, there will be

A) a copy of the field for each method in the class.
B) a copy of the field in each class object.
C) only one copy of the field in memory.
D) two reference copies of the field for each method in the class.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
A static field is created by placing the key word static

A) after the access specifier and field's data type.
B) after the access specifier and before the field's data type.
C) after the field name.
D) in brackets, before the field's data type.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
To get the name of a calling enum constant,

A) simply use the enum constant in the statement.
B) use the ordinal method.
C) use the displayName method.
D) use the toString method.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 40 flashcards in this deck.