Java Chapter 8

Your page rank:

Total word count: 1124
Pages: 4

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

Static methods can only operate on ________ fields.

global

instance

static

local

static

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.

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

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

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

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

null

0

-1

false

0

An object’s ________ is simply the data that is stored in the object’s fields at any given moment.

value

assessment

record

state

state

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.

It is necessary for an instance of the class to be created to execute the method.

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

The address of an object of the class Rectangle

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

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

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.

numAccounts = SavingsAccount.numberOfAccounts;

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

memory sweeping

system restore

memory shuffling

garbage collection

garbage collection

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

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

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.

A reference to an object of that class

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

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

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

1

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

a case expression

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.

OAK

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.

They are called from an instance of the class.

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

enum

enum_type

enumerated

ENUM

enum

The term for the relationship created by object aggregation is:

is a

Sub-class object

has a

Inner class

has a

You cannot use the == operator to compare the contents of:

objects

strings

Boolean values

integers

objects

The names of the enum constants in an enumerated data type must be enclosed in quotation marks.
True
False

False

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

True

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

True

The this key word is the name of a reference variable that is available to all static methods.
True
False

False

A single copy of a class’s static field is shared by all instances of the class.
True
False

True

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

False

The key word this is the name of a reference variable that an object can use to refer to itself.
True
False

False

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

True

Enum constants have a toString method.
True
False

True

You can declare an enumerated data type inside of a method.
True
False

False

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