Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

implicit and explicit conversion, boxing, unboxing, and autoboxing a concept in java

String s = "hello";
String s1 = new String("hello");
String s2= "hello";

implicit and explicit conversion:-

boxing, unboxing, and autoboxing a concept in java:-

implicit or boxing:-  it is used to convert primitive type data to object type.

it will be automatically implemented hence it is called an implicit conversion.

int a=10;
Object o;
o=a;  //implicit

explicit or unboxing:-  it is used to convert derived type data to a primitive type.

for example, if we convert Object type data to integer type then it is called explicit conversion

Object o=20;

int b;

b =(int)o;  //explicit

Autoboxing:-  It is used to convert all primitive type data to respective wrapper classes, for example, if we convert int data to Integer, float data to Float, char data to String then these operations will be implemented automatically.  this concept is mostly used in the collection framework in java.

int a=100;

Integer a1 = new Integer(a);

class Boxingunboxing
   Object o=20;
   int a=100,b;
   void boxing()
       o=a;  //small scale to large
       System.out.println("result is "+o);

   void unboxing()
      b=(int)o;  //large to scale
      System.out.println("result is "+o);

   void autoboxing()
      Integer c = new Integer(a);
      Integer d=b;
   public static void main(String args[])
      Boxingunboxing obj = new Boxingunboxing();



Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post