Wrapper Classes in JAVA

Object of Wrapper class contain primitive data type. Or can say that, we wrap a primitive value into a wrapper class object.

wrapper class objec

Every wrapper class(except Character class) contains two constructers :- one take corresponding primitive data type and other takes a string parameter.

Example

  1. short s=20909//primitive type  
  2. Short ob1=new Short(s);  
  3. String str="20909";  
  4. Short ob2=new Short(str);  

  • It is Used in collection framework.

  • All the wrapper classes are declared final. All the wrapper classes except Boolean and Character are sub classes of an abstract class called Number, Boolean and Character are derived directly from the Object class.

  • Wrapper classes are immutable.

    Examples of wrapper classes.

    //all programs run on netbean 8.0.2
Ebook Download
View all
Learn
View all