Q:

Java find output programs (Autoboxing & Unboxing) | set 2

belongs to collection: Java find output programs

0

Find the output of Java programs | Autoboxing & Unboxing | Set 2: Enhance the knowledge of Java Autoboxing & Unboxing concepts by solving and finding the output of some Java programs.

Question 1:

public class BoxingEx {
  public static void main(String[] args) {
    char charVar = 'A';

    Char Obj = charVar;

    System.out.println(Obj);
  }
}

Question 2:

public class BoxingEx {
  public static void main(String[] args) {
    char charVar = 'A';

    Character Obj = charVar;
    Obj++;

    System.out.println(Obj);
  }
}

Question 3:

public class BoxingEx {
  public static void main(String[] args) {
    long value = 'A';

    Long Obj = value;

    long value1 = Obj.longValue();

    System.out.println(value1);
  }
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer Question 1:

Output:

/BoxingEx.java:5: error: cannot find symbol
    Char Obj = charVar;
    ^
  symbol:   class Char
  location: class BoxingEx
1 error

Explanation:

The above program will generate a syntax error because we used wrapper class Char instead of Character. The Char class is not available in Java. The correct code is given below,

public class BoxingEx
{
     public static void main(String []args)
     {
        char charVar = 'A';
        
        Character  Obj = charVar;

        System.out.println(Obj);
     }
}

Answer Question 2:

Output:

B

Explanation:

In the above program, we created a local variable charVar initialized with 'A'.

Character  Obj = charVar;
Obj++;

In the above statement we auto-box the variable charVar into wrapper class Character, and then increase the value of Object Obj using post-increment operator. Then the value of the object Obj will 'B' and that will be printed on the console screen.

Answer Question 3:

Output:

65

Explanation:

In the above program, we created a local variable value initialized with 'A'. Then auto-box value into object Obj. After that un-box the value of variable value and assigned to the variable value1 and then print variable value1 that will print 65, which is the ASCII value of character 'A'.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java find output programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Find output programs (Java String class)... >>
<< Java find output programs (Autoboxing & Unboxing) ...