Free Online Flashcard Deck

Java Objects, Classes, and Strings Free Online FlashCards

Study Java Objects, Classes, and Strings with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is the difference between a class and an object?

Back

A class is a blueprint that defines a type’s data and behavior; an object is an instance of that class created during program execution.

02
Front

What does assignment copy for an object reference?

Back

A class-type variable stores a reference to an object, not the object’s contents directly. Assigning one reference to another copies the reference.

03
Front

What does null mean for a Java reference?

Back

null means a reference does not currently refer to any object. Calling an instance method through that reference causes a NullPointerException.

04
Front

What defines a Java constructor?

Back

A constructor initializes a new object. It has the same name as its class, has no return type, and runs when invoked with new.

05
Front

How does Java choose among overloaded constructors?

Back

Java selects an overloaded constructor whose parameter types and number match the arguments. If any constructor is declared, Java does not automatically add a no-parameter constructor.

06
Front

How do instance and static method calls differ?

Back

An instance method is called on an object, such as text.length(). A static method belongs to the class and is called through its class name, such as Math.sqrt(81.0).

07
Front

Why does word.toUpperCase() not change word?

Back

String objects are immutable: their characters cannot be changed. Methods such as toUpperCase() return a new string, so the result must be saved to change a variable’s reference.

08
Front

What does "computer".substring(0, 4) return?

Back

substring(0, 4) returns characters at indices 0 through 3 because the start is inclusive and the end is exclusive. For "computer", the result is "comp".

09
Front

How should Java compare String contents?

Back

Use equals to compare string contents. The == operator compares object references, so it does not normally test whether two strings contain the same characters.

10
Front

What are first and second after this trace?

Back

first remains "AP" and second becomes "AP CSA". Because String is immutable, += creates a new string and assigns its reference only to second.

11
Front

What are autoboxing and unboxing?

Back

Autoboxing converts a primitive to its wrapper object, such as int to Integer. Unboxing converts a wrapper object back to its primitive, such as Integer to int.

12
Front

How do parseInt and valueOf differ?

Back

Integer.parseInt("123") returns the primitive int 123, while Integer.valueOf("123") returns an Integer wrapper object.