Deck 8: A Second Look at Classes and Objects

Full screen (f)
exit full mode
Question
When an object reference is passed to a method, the method may change the values in the object.
Use Space or
up arrow
down arrow
to flip the card.
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
__________ is the term for the relationship created by object aggregation.

A) "Has a"
B) Inner class
C) "Is a"
D) One-to-many
Question
Static methods can only operate on __________ fields.

A) instance
B) static
C) global
D) local
Question
An enumerated data type is actually a special type of class.
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
If a class has a method named finalize, it is called automatically just before a data member that has been identified as final of the class is destroyed by the garbage collector.
Question
enum constants have a toString method.
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 single copy of a class's static field is shared by all instances of the class.
Question
A class's static methods do not operate on the fields that belong to any instance of the class.
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
Both instance fields and instance methods are associated with a specific instance of a class, and they cannot be used until an instance of the class is created.
Question
The key word this is the name of a reference variable that is available to all static methods.
Question
The names of the enum constants in an enumerated data type must be enclosed in quotation marks.
Question
You can declare an enumerated data type inside a method.
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
When an object is passed as an argument, it is actually a reference to the object that is passed.
Question
If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent:
System.out.println(object1);
System.out.println(object1.toString());
Question
Java automatically stores a __________ value in all uninitialized static member variables.

A) 0
B) -1
C) null
D) false
Question
In Java it is possible to write a method that will return __________.

A) a whole number
B) a reference to an object
C) a string of characters
D) Any of these
Question
When a method's return type is a class, what is actually returned to the calling program?

A) an object of that class
B) a reference to an object of that class
C) the values in the object that the method accessed
D) nothing - the return type is simply for documentation in this situation
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
You cannot use the == operator to compare the contents of __________.

A) objects
B) strings
C) integers
D) Boolean values
Question
The whole-part relationship created by object aggregation is more often called a(n) __________ relationship.

A) "has a"
B) inner class
C) extra class
D) inside class
Question
CRC stands for __________.

A) Class, Recyclability, Collaborations
B) Class, Redundancy, Collections
C) Class, Responsibilities, Collaborations
D) Code, Reuse, Constancy
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
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
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
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 declaration for an enumerated type begins with the __________ key word.

A) enumerated
B) enum type
C) ENUM
D) enum
Question
A deep copy of an object __________.

A) is an assignment of that object to another object
B) is an operation that copies an aggregate object and all the objects that it references
C) is a bogus term and means nothing
D) is always a private method
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
When a reference variable is passed as an argument to a method __________.

A) a copy of the variable's value is passed into the method's parameter
B) the method has access to the object that the variable references
C) the method becomes a static method
D) the program terminates
Question
If the this variable is used to call a constructor, __________.

A) a compiler error will result if it is not the first statement of the constructor
B) a compiler error will result if it is the first statement of the constructor
C) nothing will happen
D) the this variable cannot be used as a constructor call
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 object's __________ is simply the data that is stored in the object's fields at any given moment.

A) value
B) assessment
C) record
D) state
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
Which of the following is not true about static methods?

A) It is not necessary for an instance of the class to be created to execute a static method.
B) They are called by placing the key word static after the access specifier in the method header.
C) They are called from an instance of the class.
D) They are often used to create utility classes that perform operations on data but have no need to collect and store data.
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 graph of a rectangle
D) an object of the class Rectangle
Question
If the following is from the method section of a UML diagram, which of the statements below is true? + add(object2:Stock) : Stock

A) This is a private method named add that accepts and returns objects of the Stock class.
B) This is a private method named Stock that adds two objects.
C) This is a public method named add that accepts and returns references to objects in the Stock class.
D) This is a public method named Stock that adds two objects.
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
Which of the following is not true about static methods?

A) They are created by placing the key word static after the access specifier in the method header.
B) It is necessary for an instance of the class to be created to execute the method.
C) They are called directly from the class.
D) They are often used to create utility classes that perform operations on data but have no need to store and collect data.
Question
If you have defined a class, SavingsAccount, with a public static data member named numberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will assign numberOfAccounts to numAccounts?

A) numAccounts = account20.numAccounts;
B) numAccounts = numOfAccounts;
C) numAccounts = SavingsAccount.numberOfAccounts;
D) numAccounts = account20;
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 implicitly called.
D) A compiler error will occur.
Question
Given the following declaration: enum Tree ( OAK, MAPLE, PINE )
What is the ordinal value of the MAPLE enum constant?

A) 0
B) 1
C) 2
D) 3
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
If you attempt to perform an operation with a null reference variable __________.

A) the resulting operation will always be zero
B) the results will be unpredictable
C) the program will terminate
D) Java will create an object to reference the variable
Question
If the following is from the method section of a UML diagram, which of the statements below 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
To compare two objects in a class, __________.

A) use the == operator (for example, object1 == object2)
B) write a method to do a byte-by-byte compare of the two objects
C) write an equals method that will make a field by field compare of the two objects
D) This cannot be done since objects consist of several fields.
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 language
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
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/52
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 8: A Second Look at Classes and Objects
1
When an object reference is passed to a method, the method may change the values in the object.
True
2
An instance of a class does not have to exist in order for values to be stored in a class's static fields.
True
3
__________ is the term for the relationship created by object aggregation.

A) "Has a"
B) Inner class
C) "Is a"
D) One-to-many
A
4
Static methods can only operate on __________ fields.

A) instance
B) static
C) global
D) local
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
5
An enumerated data type is actually a special type of class.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
6
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 52 flashcards in this deck.
Unlock Deck
k this deck
7
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 52 flashcards in this deck.
Unlock Deck
k this deck
8
If a class has a method named finalize, it is called automatically just before a data member that has been identified as final of the class is destroyed by the garbage collector.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
9
enum constants have a toString method.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
10
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 52 flashcards in this deck.
Unlock Deck
k this deck
11
A single copy of a class's static field is shared by all instances of the class.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
12
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 52 flashcards in this deck.
Unlock Deck
k this deck
13
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
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
14
Both instance fields and instance methods are associated with a specific instance of a class, and they cannot be used until an instance of the class is created.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
15
The key word this is the name of a reference variable that is available to all static methods.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
16
The names of the enum constants in an enumerated data type must be enclosed in quotation marks.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
17
You can declare an enumerated data type inside a method.
Unlock Deck
Unlock for access to all 52 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 52 flashcards in this deck.
Unlock Deck
k this deck
19
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 52 flashcards in this deck.
Unlock Deck
k this deck
20
If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent:
System.out.println(object1);
System.out.println(object1.toString());
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
21
Java automatically stores a __________ value in all uninitialized static member variables.

A) 0
B) -1
C) null
D) false
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
22
In Java it is possible to write a method that will return __________.

A) a whole number
B) a reference to an object
C) a string of characters
D) Any of these
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
23
When a method's return type is a class, what is actually returned to the calling program?

A) an object of that class
B) a reference to an object of that class
C) the values in the object that the method accessed
D) nothing - the return type is simply for documentation in this situation
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
24
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 52 flashcards in this deck.
Unlock Deck
k this deck
25
You cannot use the == operator to compare the contents of __________.

A) objects
B) strings
C) integers
D) Boolean values
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
26
The whole-part relationship created by object aggregation is more often called a(n) __________ relationship.

A) "has a"
B) inner class
C) extra class
D) inside class
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
27
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 52 flashcards in this deck.
Unlock Deck
k this deck
28
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 52 flashcards in this deck.
Unlock Deck
k this deck
29
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 52 flashcards in this deck.
Unlock Deck
k this deck
30
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 52 flashcards in this deck.
Unlock Deck
k this deck
31
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 52 flashcards in this deck.
Unlock Deck
k this deck
32
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 52 flashcards in this deck.
Unlock Deck
k this deck
33
A deep copy of an object __________.

A) is an assignment of that object to another object
B) is an operation that copies an aggregate object and all the objects that it references
C) is a bogus term and means nothing
D) is always a private method
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
34
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 52 flashcards in this deck.
Unlock Deck
k this deck
35
When a reference variable is passed as an argument to a method __________.

A) a copy of the variable's value is passed into the method's parameter
B) the method has access to the object that the variable references
C) the method becomes a static method
D) the program terminates
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
36
If the this variable is used to call a constructor, __________.

A) a compiler error will result if it is not the first statement of the constructor
B) a compiler error will result if it is the first statement of the constructor
C) nothing will happen
D) the this variable cannot be used as a constructor call
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
37
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 52 flashcards in this deck.
Unlock Deck
k this deck
38
An object's __________ is simply the data that is stored in the object's fields at any given moment.

A) value
B) assessment
C) record
D) state
Unlock Deck
Unlock for access to all 52 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 52 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following is not true about static methods?

A) It is not necessary for an instance of the class to be created to execute a static method.
B) They are called by placing the key word static after the access specifier in the method header.
C) They are called from an instance of the class.
D) They are often used to create utility classes that perform operations on data but have no need to collect and store data.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
41
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 graph of a rectangle
D) an object of the class Rectangle
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
42
If the following is from the method section of a UML diagram, which of the statements below is true? + add(object2:Stock) : Stock

A) This is a private method named add that accepts and returns objects of the Stock class.
B) This is a private method named Stock that adds two objects.
C) This is a public method named add that accepts and returns references to objects in the Stock class.
D) This is a public method named Stock that adds two objects.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
43
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 52 flashcards in this deck.
Unlock Deck
k this deck
44
Which of the following is not true about static methods?

A) They are created by placing the key word static after the access specifier in the method header.
B) It is necessary for an instance of the class to be created to execute the method.
C) They are called directly from the class.
D) They are often used to create utility classes that perform operations on data but have no need to store and collect data.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
45
If you have defined a class, SavingsAccount, with a public static data member named numberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will assign numberOfAccounts to numAccounts?

A) numAccounts = account20.numAccounts;
B) numAccounts = numOfAccounts;
C) numAccounts = SavingsAccount.numberOfAccounts;
D) numAccounts = account20;
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
46
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 implicitly called.
D) A compiler error will occur.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
47
Given the following declaration: enum Tree ( OAK, MAPLE, PINE )
What is the ordinal value of the MAPLE enum constant?

A) 0
B) 1
C) 2
D) 3
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
48
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 52 flashcards in this deck.
Unlock Deck
k this deck
49
If you attempt to perform an operation with a null reference variable __________.

A) the resulting operation will always be zero
B) the results will be unpredictable
C) the program will terminate
D) Java will create an object to reference the variable
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
50
If the following is from the method section of a UML diagram, which of the statements below 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 52 flashcards in this deck.
Unlock Deck
k this deck
51
To compare two objects in a class, __________.

A) use the == operator (for example, object1 == object2)
B) write a method to do a byte-by-byte compare of the two objects
C) write an equals method that will make a field by field compare of the two objects
D) This cannot be done since objects consist of several fields.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
52
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 language
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 52 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 52 flashcards in this deck.