Wrapper Classes

For each primitive data type there is Class and which is called as wrapper class.

Wrapper classes allows us to use of polymorphism.

Tutorial url: Wrapper Classes

Example Program:

public class WrapperClassExample {
    public void testPoly(Object s){
        if(s instanceof Integer){
            System.out.println("It is an Integer");
        }else if(s instanceof Character){
            System.out.println("It is a Character");
        }else if(s instanceof Boolean){
            System.out.println("It is a Boolean");
        }else if(s instanceof Float){
            System.out.println("It is a Float");
        }else if(s instanceof Double){
            System.out.println("It is a Double");
        }else if(s instanceof Long){
            System.out.println("It is a Long");
        }else if(s instanceof Short){
            System.out.println("It is a Short");
        }else if(s instanceof Byte){
            System.out.println("It is a Byte");
            System.out.println("Given object is not a object of Wrapper class");

public class WrapperClassTest {
    public static void main(String[] args) {
        int a = 50;
        char b = 'G';
        long c = 100;
        boolean d = true;
        short e = 20;
        byte f = 10;
        float g = 10.5f;
        double h = 13.0308340;
        WrapperClassExample wce = new WrapperClassExample();

It is an Integer
It is a Character
It is a Long
It is a Boolean
It is a Short
It is a Byte
It is a Float
It is a Double

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s