Java Ch. 8 Quiz

Your page rank:

Total word count: 1549
Pages: 6

Calculate the Price

- -
275 words
Looking for Expert Opinion?
Let us have a look at your work and suggest how to improve it!
Get a Consultant

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

c. ordinal

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

c. state

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

b. the key word static after the access specifier and before the field’s data type

CRC stands for:

a. Class, Redundancy, Collections
b. Code, Reuse, Constancy
c. Class, Recyclability, Collaborations
d. Class, Responsibilities, Collaborations

d. Class, Responsibilities, Collaborations

The term for the relationship created by object aggregation is:

a. is a
b. Sub-class object
c. has a
d. Inner class

c. has a

Java automatically stores this value in all uninitialized static member variables:

a. false
b. null
c. -1
d. 0

d. 0

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

d. the method has access to the object that the variable references

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.

c. This is a public method named add that accepts and returns references to objects in the Stock class.

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

b. write an equals method that will make a field by field compare of the two objects

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

b. write a copy method that will make a field by field copy of object1 data members into object2 data members

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.

d. OAK

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

a. is an operation that copies an aggregate object, and all the objects it references

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.

a. The account object’s toString method will be implicitly called.

A declaration for an enumerated type begins with this key word.

a. enumerated
b. ENUM
c. enum
d. enum_type

c. enum

Static methods can only operate on ________ fields.

a. local
b. global
c. static
d. instance

c. static

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.

c. numAccounts = SavingsAccount.numberOfAccounts;

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

a. a compiler error will result, if it is not the first statement of the constructor

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.

b. SavingsAccount.getNumberOfAccounts();

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)

d. Tree.PINE

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

d. they cannot refer to non-static members of the class

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

a. the program will terminate

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

e. All of these

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.

b. This is a public method that accepts a Stock object as its argument and returns a boolean value.

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

c. a has a relationship

The JVM periodically performs this process to remove unreferenced objects from memory.

a. garbage collection
b. memory sweeping
c. memory shuffling
d. system restore

a. garbage collection

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

b. only one copy of the field in memory

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

a. it must be the first statement in the constructor making the call

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.

b. A reference to an object of that class

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

b. 1

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

a. The address of an object of the class Rectangle

Share This
Flashcard

More flashcards like this

NCLEX 10000 Integumentary Disorders

When assessing a client with partial-thickness burns over 60% of the body, which finding should the nurse report immediately? a) ...

Read more

NCLEX 300-NEURO

A client with amyotrophic lateral sclerosis (ALS) tells the nurse, "Sometimes I feel so frustrated. I can’t do anything without ...

Read more

NASM Flashcards

Which of the following is the process of getting oxygen from the environment to the tissues of the body? Diffusion ...

Read more

Unfinished tasks keep piling up?

Let us complete them for you. Quickly and professionally.

Check Price

Successful message
sending