Ch. 8 – A Second Look at Classes and Objects

Your page rank:

Total word count: 1032
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

A static field is created by placing:

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

Static methods can only operate on ____________ fields.

Static

The only limitation that static methods have is:

They cannot refer to non-static members of the class

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

0

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 = SavingsAccount.numberOfAccounts;

When a reference variable is passed as an argument to a method:

The method has access to the object that the variable references

In Java, it is possible to write a method that will return:

All of the above (A whole number, A monetary value, A string of characters, A reference to an object)

When a method’s return type is a class, what is actually returned to the calling program?

A reference to an object of that class

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

State

If the following is from the method section of a UML diagram, which of the following statements is true?

+ equals(object2:Stock) : boolean

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

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

Objects

To compare two objects in a class:

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:

Write a copy method that will make a field by field copy of object1 data members into obejct2 data members

A deep copy of an object:

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

The term for the relationship created by object aggregation is:

Has a

If the this variable is used to call a constructor:

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

When a field is declared static, there will be:

Only one copy of the field in memory

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?

SavingsAccount.getNumberOfAccounts();

What will be returned from a method, if the following is the method header?

public Rectangle getRectangle()

The address of an object of the class Rectangle

The whole-part relationship created by object aggregation is more often called:

A has a relationship

If you attempt to perform an operation with a null reference variable:

The program will terminate

When the this variable is used to call a constructor:

It must be the first statement in the constructor making the call.

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

enum

Look at the following declaration:

enum Tree { OAK, MAPLE, PINE }

What is the ordinal value of the MAPLE enum constant?

1

Look at the following declaration:

enum Tree { OAK, MAPLE, PINE }

What is the fully-qualified name of the PINE enum constant?

Tree.PINE

Assuming the following declaration exists:

enum Tree { OAK, MAPLE, PINE }

What will the following code display?

System.out.println(Tree.OAK);

OAK

CRC stands for:

Class, Responsibilities, Collaborations

You cannot use the fully-qualified name of an enum constant for this.

A case expression

Enumerated types have this method, which returns the position of an enum constant in the declaration list.

Ordinal

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

Garbage collection

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

TRUE/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

TRUE/FALSE: 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

TRUE/FALSE: A single copy of a class’s static field is shared by all instances of the class.

True

TRUE/FALSE: When an object is passed as an argument, it is actually a reference to the object that is passed.

True

TRUE/FALSE: 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());

True

TRUE/FALSE: The this key word is the name of a reference variable that is available to all static methods.

False

TRUE/FALSE: 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.

False

TRUE/FALSE: A class’s static methods do not operate on the fields that belong to any instance of the class.

True

TRUE/FALSE: When an object reference is passed to a method, the method may change the values in the object.

True

TRUE/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

TRUE/FALSE: The key word this is the name of a reference variable that an object can use to refer to itself.

True

TRUE/FALSE: 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.

True

TRUE/FALSE: The names of the enum constants in an enumerated data type must be enclosed in quotation marks.

False

TRUE/FALSE: An enumerated data type is actually a special type of class.

True

TRUE/FALSE: You can declare an enumerated data type inside of a method.

False

TRUE/FALSE: Enum constants have a toString method.

True

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