Some people may ask why do you need type casting? well, you need type casting to get access to fields and methods declared on the target type or class . You can not access them with any other type. Let’s see a simple example of type casting in Java with two classes Base and Derived which share the same type hierarchy.
Read moreWhat is type casting with example?
An example of typecasting is converting an integer to a string . This might be done in order to compare two numbers, when one number is saved as a string and the other is an integer. For example, a mail program might compare the first part of a street address with an integer.
Read more