• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/31

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

31 Cards in this Set

  • Front
  • Back

This type of method cannot access any non-static member variables in its own class.a. instanceb. voidc. staticd. non-static

c

When an object is passed as an argument to a method, this is actually passed.a. a copy of the objectb. the name of the objectc. a reference to the objectd. none of these; you cannot pass an object

c

If you write this method for a class, Java will automatically call it any time you concatenate an object of the class with a string. a. toString b. plusString c. stringConvert d. concatString

a

Making an instance of one class a field in another class is called ___________.a. nestingb. class fieldingc. aggregationd. concatenation

c

This is the name of a reference variable that is always available to an instance method and refers to the object that is calling the method. a. callingObject b. this c. me d. instance

b

This enum method returns the position of an enum constant in the declaration.a. positionb. locationc. ordinald. toString

c

Assuming the following declaration exists:enum Seasons { SPRING, WINTER, SUMMER, FALL } what is the fully qualified name of the FALL constant?a. FALLb. enum.FALLc. FALL.Seasonsd. Seasons.FALL

d

You cannot use the fully qualified name of an enum constant for this.a. a switch expressionb. a case expressionc. an argument to a methodd. all of these

b

The Java Virtual Machine periodically performs this process, which automaticallyremoves unreferenced objects from memory.a. memory cleansingb. memory deallocationc. garbage collectiond. object expungement

c

If a class has this method, it is called automatically just before an instance of the class is destroyed by the Java Virtual Machine. a. finalize b. destroy c. remove d. housekeeper

a

CRC stands fora. Class, Return value, Compositionb. Class, Responsibilities, Collaborationsc. Class, Responsibilities, Compositiond. Compare, Return, Continue

b

True or False: A static member method may refer to non-static member variables ofthe same class, but only after an instance of the class has been defined.

False

True or False: All static member variables are initialized to –1 by default

False

True or False: When an object is passed as an argument to a method, the method canaccess the argument.

True

True or False: A method cannot return a reference to an object.

False

True or False: You can declare an enumerated data type inside a method

False

True or False: Enumerated data types are actually special types of classes.

True

True or False: enum constants have a toString method.

True

The following class definition has an error. What is it?1. public class MyClass{ private int x; private double y; public static void setValues(int a, double b) { x = a; y = b; }}

The static method setValues cannot refer to the non-static fields x and y

Assume the following declaration exists :enum Coffee { MEDIUM, DARK, DECAF } Find the error(s) in the following switch statement:// This code has errors!Coffee myCup = DARK;switch (myCup){ case Coffee.MEDIUM : System.out.println("Mild flavor."); break; case Coffee.DARK : System.out.println("Strong flavor."); break; case Coffee.DECAF : System.out.println("Won’t keep you awake."); break; default: System.out.println("Never heard of it.");}

You cannot use the fully-qualified names of enumconstants in the caseexpressions.

Describe one thing you cannot do with a static method.

Access a non-static member.

Why are static methods useful in creating utility classes?

They can be called directly from the class, as needed. They can be used to create utility classes that perform operations on data, but have no need to collect and store data.

Describe the difference in the way variables and class objects are passed as argumentsto a method.

When a variable is passed as an argument, a copyof the variable's contents is passed. The receiving method does not have accessto the variable itself. When an object is passed as an argument, a reference tothe object (which is the object's address) is passed. This allows the receivingmethod to have access to the object.

Even if you do not write an equals method for a class, Java provides one. Describethe behavior of the equals method that Java automatically provides.

The default equals method returns true if the memory addresses of the two objects beingcompared are the same.

A “has a” relationship can exist between classes. What does this mean?

It means that anaggregate relationship exists. When an object of class B is a member of classA, it can be said that class A "has a" class B object.

What happens if you attempt to call a method using a reference variable that is setto null?

The program will crash.

Is it advisable or not advisable to write a method that returns a reference to an objectthat is a private field? What is the exception to this?

It is not advisable because it will allow accessto the private fields. The exception to this is when the field is a String object. This is because String objects are immutable, meaning that they cannot bechanged.

What is the this key word?

The key word this is the name of a referencevariable that an object can use to refer to itself. It is available to allnon-static methods.

Look at the following declaration:enum Color { RED, ORANGE, GREEN, BLUE }a. What is the name of the data type declared by this statement?b. What are the enum constants for this type?c. Write a statement that defines a variable of this type and initializes it with a valid value.

a) Color b) Color.RED, Color.ORANGE, Color.GREEN,Color.BLUE c) Color myColor = Color.BLUE;

Assuming the following enum declaration exists:enum Dog { POODLE, BOXER, TERRIER } what will the following statements display?a. System.out.println(Dog.POODLE + "\n" + Dog.BOXER + "\n" + Dog.TERRIER);b. System.out.println(Dog.POODLE.ordinal() + "\n” + Dog.BOXER.ordinal() + "\n" + Dog.TERRIER.ordinal());c. Dog myDog = Dog.BOXER;if (myDog.compareTo(Dog.TERRIER) > 0) System.out.println(myDog + " is greater than " + Dog.TERRIER);else System.out.println(myDog + " is NOT greater than " + Dog.TERRIER);

a) POODLE BOXER TERRIER b) 0 1 2 c) BOXER is NOT greater than TERRIER

Under what circumstances does an object become a candidate for garbage collection?

When there are no references to it.