Home > DeveloperSection > Interviews > Can you explain about Implicit and Explicit type casting ?

Posted on    July-03-2015 12:34 AM

 Java Java 
Ratings:
 1 Answer(s)
  308  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Points:4035
Posted on    July-03-2015 12:34 AM

Implicit casting (widening conversion) :
When JVM encounters a data type of lower size which occupies less memory, it is assigned to a data type of higher size implicitly by the JVM. This is also known as automatic type conversion. For Example
int i = 1; // 4 bytes
double d = i; // 8 bytes

Explicit casting:
When a data type of higher size which occupies more memory, needs to be assigned to a data type of lower size, it is called explicit casting. This type of casting won't be done implicitly by the JVM. This casting operation should be performed by the programmer. For example 
double d = 1.0; 
int i = (int) d;

Don't want to miss updates? Please click the below button!

Follow MindStick