Java Ch. 8 Quiz

25 July 2022
4.7 (114 reviews)
30 test answers

Unlock all answers in this set

Unlock answers (26)
question
Enumerated types have this method, which returns the position of an enum constant in the declaration list. a. location b. toString c. ordinal d. position
answer
c. ordinal
question
An object's ________ is simply the data that is stored in the object's fields at any given moment. a. assessment b. value c. state d. record
answer
c. state
question
A static field is created by placing: a. the key word static after the field name b. the key word static after the access specifier and before the field's data type c. the key word static after the access specifier and field's data type d. it in a static field block
answer
b. the key word static after the access specifier and before the field's data type
question
CRC stands for: a. Class, Redundancy, Collections b. Code, Reuse, Constancy c. Class, Recyclability, Collaborations d. Class, Responsibilities, Collaborations
answer
d. Class, Responsibilities, Collaborations
question
The term for the relationship created by object aggregation is: a. is a b. Sub-class object c. has a d. Inner class
answer
c. has a
question
Java automatically stores this value in all uninitialized static member variables: a. false b. null c. -1 d. 0
answer
d. 0
question
When a reference variable is passed as an argument to a method: a. the method becomes a static method b. the program will terminate c. a copy of the variable's value is passed into the method's parameter d. the method has access to the object that the variable references
answer
d. the method has access to the object that the variable references
question
If the following is from the method section of a UML diagram, which of the following statements 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.
answer
c. This is a public method named add that accepts and returns references to objects in the Stock class.
question
To compare two objects in a class: a. use the == operator, e.g. object1 == object2 b. write an equals method that will make a field by field compare of the two objects c. Since objects consist of several fields, you cannot compare them d. write a method to do a byte-by-byte compare of the two objects
answer
b. write an equals method that will make a field by field compare of the two objects
question
If object1 and object2 are objects of the same class, to make object2 a copy of object1: a. use the default constructor to create object2 with object1 data members b. write a copy method that will make a field by field copy of object1 data members into object2 data members c. assign object1 to object2, such as object2 = object1; d. use the Java copy method that is a part of the Java language
answer
b. write a copy method 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? System.out.println(Tree.OAK); a. Tree.OAK b. 0 c. 1 d. OAK e. Nothing. This statement will cause an error.
answer
d. OAK
question
A deep copy of an object: a. is an operation that copies an aggregate object, and all the objects it references b. is always a private method c. is an assignment of that object to another object d. is a bogus term, it has no meaning
answer
a. is an operation that copies an aggregate object, and all the objects it references
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. The account object's toString method will be implicitly called. b. A compiler error will occur. c. The method will display unreadable binary data on the screen. d. A runtime error will occur.
answer
a. The account object's toString method will be implicitly called.
question
A declaration for an enumerated type begins with this key word. a. enumerated b. ENUM c. enum d. enum_type
answer
c. enum
question
Static methods can only operate on ________ fields. a. local b. global c. static d. instance
answer
c. static
question
If you have defined a class named 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 = numberOfAccounts; c. numAccounts = SavingsAccount.numberOfAccounts; d. None of these, you cannot reference a static data member.
answer
c. numAccounts = SavingsAccount.numberOfAccounts;
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. nothing will happen c. the this variable cannot be used as a constructor call d. a compiler error will result, if it is the first statement of the constructor
answer
a. a compiler error will result, if it is not the first statement of the constructor
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. getNumberOfAccounts(); b. SavingsAccount.getNumberOfAccounts(); c. getNumberOfAccounts(account20); d. None of these, you cannot call a static method.
answer
b. SavingsAccount.getNumberOfAccounts();
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. PINE.Tree d. Tree.PINE e. Tree(PINE)
answer
d. Tree.PINE
question
The only limitation that static methods have is: a. they can refer to only non-static members of the class b. they must be declared as public methods c. they can only be called from static members of the class d. they cannot refer to non-static members of the class
answer
d. they cannot refer to non-static members of the class
question
If you attempt to perform an operation with a null reference variable: a. the program will terminate b. the resulting operation will always be zero c. Java will create an object to reference the variable d. the results will be unpredictable
answer
a. the program will terminate
question
In Java, it is possible to write a method that will return: a. a whole number b. a monetary value c. a string of characters d. a reference to an object e. All of these
answer
e. All of these
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 private method that returns a boolean value. b. This is a public method that accepts a Stock object as its argument and returns a boolean value. c. This is a public method that returns a Stock object. d. This is a private method that receives two objects from the Stock class and returns a boolean value.
answer
b. This is a public method that accepts a Stock object as its argument and returns a boolean value.
question
The whole-part relationship created by object aggregation is more often called: a. an inner class relationship b. an extra class relationship c. a has a relationship d. an inside class relationship
answer
c. a has a relationship
question
The JVM periodically performs this process to remove unreferenced objects from memory. a. garbage collection b. memory sweeping c. memory shuffling d. system restore
answer
a. garbage collection
question
When a field is declared static, there will be: a. only two copies of the field in memory b. only one copy of the field in memory c. a copy of the field for each static method in the class d. a copy of the field in each class object
answer
b. only one copy of the field in memory
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
answer
a. it must be the first statement in the constructor making the call
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. Only the values in the object that the method accessed d. Nothing, the return type is strictly for documentation in this situation.
answer
b. A reference to an object of that class
question
Look at 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 e. Tree.MAPLE
answer
b. 1
question
What will be returned from a method, if the following is the method header? public Rectangle getRectangle() a. The address of an object of the class Rectangle b. The values stored in the data members of the Rectangle object the method changed c. A graph of a rectangle d. An object of the class Rectangle
answer
a. The address of an object of the class Rectangle