public class Step29 {

    public static void main(String[] args) {
        
        /* Problem 1 */

        Object o = 1 + new Integer(2);
        System.out.println(o);

        /* Here autoboxing upgrades "1" to "new Integer(1)", and the
           resulting Integer is assigned to o. If you call
           System.out.println(o), where o is an Object, then println
           calls the o.toString() to figure out what to print. In our
           case, the Integer.toString() method will return "3", so
           that is what's printed. */


        int x = 1 + new Integer(2);
        System.out.println(x);

        /* Here autoboxing downgrades "new Integer(2)" to "2", and the
           resulting int is assigned to x. If you call
           System.out.println(x), where x is an int, it prints the
           value of x, i.e. "3". */
        

        /* Problem 2 */

        /* The compiler cannot prevent you from unboxing a null Integer.
           This will cause a runtime NullPointerException */
        Integer n = null;
        int y = 1 + n;
    }

}
