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;
6 Cards in this Set
- Front
- Back
- 3rd side (hint)
What is the function of 'boxing'?
|
To convert value types to reference types.
|
Add value to a box.
|
|
What is a reference type?
|
A reference type is variable that stores a reference to a location (similar to an address) that stores the actual data.
|
You're cute. What's your address?
|
|
Show a simple example of boxing an integer type.
|
long myLong = 3;
... object myObj = myLong; //implicit boxing of myLong. |
|
|
True or False. Unboxing requires an explicit cast.
|
True.
int myFoo = 3, myBar; object myObj = myFoo; //Following won't compile. myBar = myObj; //Following compiles myBar = (int) myObj; |
|
|
Will this code snippet compile?
int myBar = 3; object myObj = myBar; int k = (short) myObj; |
No.
//Following gives InvalidCastException k = (short) myObj; Although there is an implicit cast from short to int even an explicit cast is not allowed during an unboxing operation. |
|
|
Which of these statements is a valid boxing operation?
int myFoo; object myObj; object yourObj = 4; a. myObj = myFoo; b. myFoo = 3; myObj = myFoo; c. myObj = yourObj; d. myObj = 4; |
b and d. In statement d, the literal '4' gets boxed into myObj. myObj can the be unboxed into any appropriate integer variable.
|
|