Data Types Flashcards
What are the two constructors of the Boolean wrapper class?
Boolean (boolean)
and Boolean (String)
This second constructor is deprecated but still shows up on the exam.
What are the two static helper methods for the Boolean wrapper class?
parseBoolean and valueOf
What does the Boolean.parseBoolean(String) method do?
It returns a primitive type that is equal to the value true if, and only if, the string argument is not null and returns “true” (as a constant Boolean.TRUE), regardless of case.
What type do the parseWrappername( ) methods (e.g. parseInteger ( ) or parseBoolean( ) ) return?
Primitive types, not objects.
What do Boolean.valueOf(String) and its overloaded method Boolean.valueOf(boolean) return?
A reference to either Boolean.TRUE or Boolean.FALSE (constants of the wrapper class Boolean).
What does the following evaluate to?
new Boolean(“true”) == Boolean.TRUE
It evaluates to false.
Both have a Boolean wrapper object containing the value true, but they are different objects.
Do any wrapper classes have a no-args constructor?
No.
What parameters does Long.valueOf( ) takes?
None.
This means that Long.valueOf(“123”) does not compile.
Can variables be assigned as abstract?
No.
If a class is not nested, what modifiers can it have that are legal?
final, abstract, and public.
If a class is nested, what modifiers can it have?
Public, private, protected, abstract, and final.
How can an object be made eligible for garbage collection?
By making sure there are no references pointing to it.
Is the following code valid?
Integer i = new Integer(42); Long ln = new Long(42); i == ln;
No. ln and i are references to different classes of unrelated objects.
If the compiler can figure out that something can NEVER happen, it flags an error.
What is the signature of the equals( ) method?
boolean equals(Object o);
This means it can take any Object as an argument.
How does the equals( ) method of a wrapper class work?
It first checks if the two objects are of the same wrapper class. If not, it returns false.