CAN YOU EXPLAIN ABOUT IMPLICIT AND EXPLICIT TYPE CASTING ?

Mayank Tripathi

Total Post:807

Points:4035
Posted by  Mayank Tripathi
Java 
 481  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    Can you explain about Implicit and Explicit type casting ?

    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;

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!