DEV Community

Bharath kumar
Bharath kumar

Posted on

Type casting

Today we discuss about the type casting in java programming
example:
Type casting in Java is the process of converting a variable from one data type to another.
Types of Type Casting:

There are two types of Type Casting in Java:

  1. Widening Type Casting
  2. Narrow Type Casting

    int myInt = 9;
    double myDouble = myInt; // Automatic widening casting
    Widening casting:
    converting a smaller data type to a larger data type.

Narrowing Casting:
when converting a larger data type to a smaller data type double myDouble = 10.99;
int myInt = (int) myDouble; // Explicit narrowing casting

reference:https://www.geeksforgeeks.org/java/typecasting-in-java/

Mainly there are two types of Explicit Casting:

narrow casting types:
1.Explicit Upcasting
2.Explicit Downcasting
this type of upcasting and downcasting is used only inheritance concepts or normally type casting types ?

Top comments (0)