Java Chapter 8

24 July 2022
4.7 (114 reviews)
29 test answers

Unlock all answers in this set

Unlock answers (25)
question
Static methods can only operate on ________ fields. global instance static local
answer
static
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); The account object's toString method will be implicitly called. A compiler error will occur. The method will display unreadable binary data on the screen. A runtime error will occur.
answer
The account object's toString method will be implicitly called.
question
To compare two objects in a class: Since objects consist of several fields, you cannot compare them write a method to do a byte-by-byte compare of the two objects write an equals method that will make a field by field compare of the two objects use the == operator, e.g. object1 == object2
answer
write an equals method that will make a field by field compare of the two objects
question
An object's ________ is simply the data that is stored in the object's fields at any given moment. value assessment record state
answer
state
question
Which of the following is NOT true about static methods? They are created by placing the key word static after the access specifier in the method header. They are called directly from the class. They are often used to create utility classes that perform operations on data, but have no need to collect and store data. It is necessary for an instance of the class to be created to execute the method.
answer
It is necessary for an instance of the class to be created to execute the method.
question
What will be returned from a method, if the following is the method header? public Rectangle getRectangle() An object of the class Rectangle The values stored in the data members of the Rectangle object the method changed A graph of a rectangle The address of an object of the class Rectangle
answer
The address of an object of the class Rectangle
question
A deep copy of an object: is always a private method is a bogus term, it has no meaning is an assignment of that object to another object is an operation that copies an aggregate object, and all the objects it references
answer
is an operation that copies an aggregate object, and all the objects it references
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? numAccounts = account20.numAccounts; numAccounts = numberOfAccounts; numAccounts = SavingsAccount.numberOfAccounts; None of these, you cannot reference a static data member.
answer
numAccounts = SavingsAccount.numberOfAccounts;
question
The JVM periodically performs this process to remove unreferenced objects from memory. memory sweeping system restore memory shuffling garbage collection
answer
garbage collection
question
A static field is created by placing: the key word static after the field name the key word static after the access specifier and before the field's data type the key word static after the access specifier and field's data type it in a static field block
answer
the key word static after the access specifier and before the field's data type
question
When a method's return type is a class, what is actually returned to the calling program? An object of that class A reference to an object of that class Only the values in the object that the method accessed Nothing, the return type is strictly for documentation in this situation.
answer
A reference to an object of that class
question
If object1 and object2 are objects of the same class, to make object2 a copy of object1: use the Java copy method that is a part of the Java language assign object1 to object2, such as object2 = object1; use the default constructor to create object2 with object1 data members write a copy method that will make a field by field copy of object1 data members into object2 data members
answer
write a copy method that will make a field by field copy of object1 data members into object2 data members
question
Look at the following declaration: enum Tree { OAK, MAPLE, PINE } What is the ordinal value of the MAPLE enum constant? 0 1 2 3 Tree.MAPLE
answer
1
question
You cannot use the fully-qualified name of an enum constant for this. a switch expression an argument to a method a case expression all of these
answer
a case expression
question
Assuming the following declaration exists: enum Tree { OAK, MAPLE, PINE } What will the following code display? System.out.println(Tree.OAK); Tree.OAK 0 1 OAK Nothing. This statement will cause an error.
answer
OAK
question
Which of the following is NOT true about static methods? They are created by placing the key word static after the access specifier in the method header. They are called from an instance of the class. They are often used to create utility classes that perform operations on data, but have no need to collect and store data. It is not necessary for an instance of the class to be created to execute the method.
answer
They are called from an instance of the class.
question
A declaration for an enumerated type begins with this key word. enum enum_type enumerated ENUM
answer
enum
question
The term for the relationship created by object aggregation is: is a Sub-class object has a Inner class
answer
has a
question
You cannot use the == operator to compare the contents of: objects strings Boolean values integers
answer
objects
question
The names of the enum constants in an enumerated data type must be enclosed in quotation marks. True False
answer
False
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
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. True False
answer
True
question
The this key word is the name of a reference variable that is available to all static methods. True False
answer
False
question
A single copy of a class's static field is shared by all instances of the class. True False
answer
True
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. True False
answer
False
question
The key word this is the name of a reference variable that an object can use to refer to itself. True False
answer
False
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
Enum constants have a toString method. True False
answer
True
question
You can declare an enumerated data type inside of a method. True False
answer
False