✏️ Explanatory Question

[Primitive Values, Wrapper Classes, Types and Casting]

While using Wrapper classes, we do not need to import any package. Give a reason.

👁 0 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation

Because Wrapper classes are part of the java.lang package, which is imported automatically by Java.

Understanding Wrapper Classes:

Wrapper classes convert primitive data types into objects.

Primitive Type Wrapper Class
int Integer
double Double
char Character

java.lang Package:

All wrapper classes belong to the:

java.lang package

Important Feature of java.lang:

  • Automatically imported in every Java program
  • No need to write import java.lang.*;

Example:

Double d = Double.parseDouble("12.5");

Here, no import statement is required.

Why This Works:

Point Explanation
Wrapper classes location java.lang package
Package behavior Auto-imported by default

Conclusion:

  • Wrapper classes are in java.lang
  • java.lang is automatically available
  • Hence, no import statement is required ✅