Autobox unbox occurs inside expressions. : Autobox Unbox « Data Type « Java






Autobox unbox occurs inside expressions.

Autobox unbox occurs inside expressions.
 

public class AutoBox3 { 
  public static void main(String args[]) { 
     
    Integer iOb, iOb2; 
    int i; 
 
    iOb = 100; 
    System.out.println("Original value of iOb: " + iOb); 
 
    // The following automatically unboxes iOb, performs the increment, and then reboxes 
    // the result back into iOb. 
    ++iOb; 
    System.out.println("After ++iOb: " + iOb); 
 
    // Here, iOb is unboxed, the expression is evaluated, and the result is reboxed and 
    // assigned to iOb2. 
    iOb2 = iOb + (iOb / 3); 
    System.out.println("iOb2 after expression: " + iOb2); 
 
    // The same expression is evaluated, but the result is not reboxed. 
    i = iOb + (iOb / 3); 
    System.out.println("i after expression: " + i); 
 
  } 
}


           
         
  








Related examples in the same category

1.What is Autoboxing?
2.Type conversion (JDK1.5 Autoboxing/Unboxing)
3.Demonstrate autobox and unbox.Demonstrate autobox and unbox.
4.Autobox unbox takes place with method parameters and return values.Autobox unbox takes place with method parameters and return values.
5.Autobox unbox: convertAutobox unbox: convert
6.Autobox unbox a Boolean and Character. Autobox unbox a Boolean and Character.
7.An error produced by manual unboxing. An error produced by manual unboxing.
8.Java Autobox and UnboxJava Autobox and Unbox
9.Autobox DemoAutobox Demo
10.Autoboxing/unboxing takes place with method parameters and return values.
11.Autoboxing/unboxing occurs inside expressions.
12.Auto-unboxing allows you to mix different types of numeric objects in an expression.