What is casting in Java?

1 votes
243 views
Mitul Chopra asked 21-Dec-2017 in Technology by Mitul Chopra

What is casting in Java?

1 Answer

0 votes
Harsh kumar srivastava answered 21-Dec-2017 by Harsh kumar srivastava

hi Mitul,

Well, this topic is not specific to Java, as many other programming languages support casting of their variable types. But Now we concentrate on Casting in Java,

Casting is a process in which taking an object of one particular type and "turning it into" another object type.

In Java, there are two types of casting, casting between object references and casting between primitive numeric types. In casting between object references is used to refer an object by a compatible class, interface, or array type reference. And Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values.

Casting is often necessary to process when a function returns a data of a type different from then we need to cast the data of the desired one. In Java, under certain circumstances, Type conversion can be carried out implicitly, but in other cases, it must be done explicitly.

We can use Casting when we want to get more specific functionality out of a generic Object.

Hope it's informative...