Computer Applications
Answer
Differences between boxing and unboxing are:
Boxing | Unboxing |
---|---|
It is the process of converting a primitive type to its corresponding wrapper class object. | It is the process of converting a wrapper class object back to its corresponding primitive type. |
It occurs when assigning a primitive value to a wrapper object. | It occurs when assigning a wrapper object to a primitive variable. |
Example: int num = 10; Integer obj = num; | Example: Integer obj = 20; int num = obj; |
Related Questions
String s1 = "45.50"; String s2 = "54.50"; double d1=Double.parseDouble(s1); double d2=Double.parseDouble(s2); int x= (int)(d1+d2);
What is value of x?
Consider the following two-dimensional array and answer the questions given below:
int x[ ][ ] = {{4,3,2}, {7,8,2}, {8, 3,10}, {1, 2, 9}};
(a) What is the order of the array?
(b) What is the value of x[0][0]+x[2][2]?
The following code to compare two strings is compiled, the following syntax error was displayed – incompatible types – int cannot be converted to boolean.
Identify the statement which has the error and write the correct statement. Give the output of the program segment.
void calculate() { String a = "KING", b = "KINGDOM"; boolean x = a.compareTo(b); System.out.println(x); }
Consider the given program and answer the questions given below:
class temp { int a; temp() { a=10; } temp(int z) { a=z; } void print() { System.out.println(a); } void main() { temp t = new temp(); temp x = new temp(30); t.print(); x.print(); } }
(a) What concept of OOPs is depicted in the above program with two constructors?
(b) What is the output of the method main()?