Type casting in Java

By | July 12, 2020

Type casting in Java:

Automatic, non-explicit change of data type is known as Conversion.

Type casting is of two types.

1. Widening / Implicit / Automatic type casting

2. Narrowing / Explicit / Manual type casting.

 

1 Implicit type casting:

Variable of smaller capacity can be assigned to another variable of bigger capacity.

byte -> short -> char -> int -> long -> float -> double

2 Explicit type casting:

Whenever a larger data type is converted to smaller type then we have to explicitly specify the type case operator.

double -> float -> long -> int -> char -> short -> byte

 

Recommended Posts:

How to remove last element from an ArrayList

Remove element from ArrayList

How to swap two numbers without using third variable in Java ***

How to capitalize each word in Java

Java interview questions

Generate random between 1 to 10 in Java

 

Note: If you like selenium99.com and want to contribute any articles, then please send your articles to techygeeks99@gmail.com. 

If you want to improve this article or find any mistake in the article, then please use comment box to share your feedback.

Links: TestNG

Tags: Type casting in Java

Leave a Reply

Your email address will not be published. Required fields are marked *