Study your flashcards anywhere!

Download the official Cram app for free >

  • 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

How to study your flashcards.

Right/Left arrow keys: Navigate between flashcards.right arrow keyleft arrow key

Up/Down arrow keys: Flip the card between the front and back.down keyup key

H key: Show hint (3rd side).h key

A key: Read text to speech.a key


Play button


Play button




Click to flip

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.
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;

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