Wrapper Class In Java
Wraper classes in java
-----------------------------------------
There is a wrapper class for every primitive in Java. The wrapper class for int is Integer and the class for float is Float and so on. Wrapper classes also provide many utility functions for primitives like Integer.parseInt().
Ex: Write a method which will accept anything. We can write the method as
public method(Object obj)
{
}
Now as all classes are children of Object class, their objects can be passed in the above program. However primitive types(like int,float...etc) are not children of Object and hence cannot be passed. We can wrap the primitives inside corresponding wrapper classes(like Integer,Float....etc) and then can pass to the function.
Comments
Post a Comment