Q. What is Autoboxing and unboxing?

Autoboxing and unboxing in Java are features that provide automatic conversion between primitive types and their corresponding wrapper classes (objects) without the need for explicit casting.

Autoboxing:

Autoboxing is the automatic conversion of a primitive type to its corresponding wrapper class object. it allows us to assign a primitive value to a wrapper class object directly.


   int num = 10;

    Integer obj = num; // Autoboxing

 

Unboxing:

Unboxing is the automatic conversion of a wrapper class object back to its corresponding primitive type. It allows you to extract the primitive value from the wrapper object directly.

For example:

Integer obj = 20;

int num = obj; // Unboxing