Deck 6: A Second Look at Classes and Objects

Full screen (f)
exit full mode
Question
When an object is passed as an argument, it is actually a reference to the object that is passed.
Use Space or
up arrow
down arrow
to flip the card.
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 only to nonstatic members of the class
Question
You can declare an enumerated data type inside a method.
Question
The JVM periodically performs the __________ process to remove unreferenced objects from memory.

A) memory shuffling
B) system restore
C) garbage collection
D) memory sweeping
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
A class's static methods do not operate on the fields that belong to any instance of the class.
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
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
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
CRC stands for

A) Class, Recyclability, Collaborations
B) Class, Redundancy, Collections
C) Class, Responsibilities, Collaborations
D) Code, Reuse, Constancy
Question
enum constants have a toString method.
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 these
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
__________ is the term for the relationship created by object aggregation.

A) "Has a"
B) Inner class
C) "Is a"
D) One-to-many
Question
When you make a copy of the aggregate object and of the objects that 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
An enumerated data type is actually a special type of class.
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
A class that is defined inside another class is called a(n)

A) nested class
B) enumerated class
C) inner class
D) helper class
Question
The key word this is the name of a reference variable that an object can use to refer to itself.
Question
The names of the enum constants in an enumerated data type must be enclosed in quotation marks.
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) public Rectangle(length, width)
Question
When a method's type is an object, what is actually returned by 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
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
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
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) SavingsAccount.account20.getNumberOfAccounts();
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) None of these. You cannot use the this variable in a constructor call.
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
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) Any of these
Question
Which of the following can you use 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
Enumerated types have the __________ method which returns the position of an enum constant in the declaration list.

A) position
B) location
C) ordinal
D) index
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
If the following is from the method section of a UML diagram, which of the statements shown 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
A declaration for an enumerated type begins with the __________ key word.

A) enumerated
B) enum type
C) ENUM
D) enum
Question
Given the following method header, what will be returned from the method? 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
Given 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
Assume 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
You can use the enum key word to

A) create your own data type
B) specify the values that belong to the type
C) Both of these
D) Neither of these
Question
Assume the class BankAccount has been created and the following statement correctly creates an instance of the class. BankAccount account = new BankAccount(5000.00);
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 implicity called.
D) A compiler error will occur.
Question
A static field is created by placing the key word static

A) after the access specifier and the 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
By default, a reference variable that is an instance field is initialized to the value

A) null
B) 0
C) static
D) void
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
When an object is passed as an argument, it is actually a reference to the object that is passed.
True
2
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 only to nonstatic members of the class
B
3
You can declare an enumerated data type inside a method.
False
4
The JVM periodically performs the __________ 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
5
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
6
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
7
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
8
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
9
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
10
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
11
enum constants have a toString method.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
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 these
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
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
14
__________ 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
15
When you make a copy of the aggregate object and of the objects that 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
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
17
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
18
A class that is defined inside 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
19
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
20
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
21
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) public Rectangle(length, width)
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
When a method's type is an object, what is actually returned by 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
23
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
24
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
25
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) SavingsAccount.account20.getNumberOfAccounts();
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
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) None of these. 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
27
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
28
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) Any of these
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following can you use 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
Enumerated types have the __________ 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
31
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
32
If the following is from the method section of a UML diagram, which of the statements shown 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
33
A declaration for an enumerated type begins with the __________ 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
34
Given the following method header, what will be returned from the method? 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
35
Given 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
36
Assume 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
37
You can use the enum key word to

A) create your own data type
B) specify the values that belong to the type
C) Both of these
D) Neither of these
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
Assume the class BankAccount has been created and the following statement correctly creates an instance of the class. BankAccount account = new BankAccount(5000.00);
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 implicity called.
D) A compiler error will occur.
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 the 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
By default, a reference variable that is an instance field is initialized to the value

A) null
B) 0
C) static
D) void
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.