Important Java Concept

Type casting in Java

Type casting is the conversion from 1 data type to another.

It is of 2 types :
1. Widening
2. Narrowing

Widening

In case of widening, we convert smaller datatype like an integer to bigger data type like double.

int a = 4;
double b = a;
System.out.println(b);

Output

4.0

Narrowing

In case of narrowing we convert bigger datatype like double to smaller data type like an integer.

double c = 3.445;
int d = (int) c;
System.out.println(d);

Output:

3

Conclusion:

Here, we learned about Type Casting. In the next article, we’ll learn about operators.

Do you want

Java Tutor?

Aniket Malik

Aniket Malik

ORACLE CERTIFIED JAVA TUTOR

🟢 Oracle Certified Java Expert

🟢 300 + ⭐ ⭐ ⭐ ⭐ ⭐

🟢 B.tech & M.tech in CSE

🟢 6+ Years of Teaching Experience

🟢 Worked as SE in Virtusa and Digidez

Do you want

Java Tutor?