Java Type Casting

The Primitive datatypes in Java are the following: byte, short, int, long, float, double, boolean, and char. Type Casting is to convert one data type to another. There are two types of Type Casting in Java:

  • Automatic Type Casting
  • Manual Type Casting

Automatic/ Widening Type Casting in Java

The Widening type casting is handled by Java on its own i.e., it occurs when you want to convert a smaller type to a larger type.

The flow for Widening type casting in Java includes:

Widening Typecasting in Java

 

Let us see an example of the Automatic/ Widening Type Casting in Java:

Output

Manual/ Narrowing Type Casting in Java

The narrowing type casting is handled by Java on its own i.e., it occurs when you want to convert a larger type to a smaller type.

The flow for Automatic type casting in Java includes:

Narrowing Typecasting in Java

Let us see an example of the Manual/ Narrowing Type Casting in Java:

Output



If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More

Java Comments
Java Threading
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading