What is casting? What are the different types of Casting?

What is casting? What are the different types of Casting?

Type casting: Explicit conversion between incompatible types ( or ) changing entities from one data type to another data type.

Example:
byte number;
number = 14; // error – 14 is int type and number is of byte
number = (byte)14; // correct type casting

Types of casting :

1. Implicit casting: This is the process of assigning one entity to another. No transformation guidance is needed.

Example:
int number = 1000;
long longNumber = number; //Implicit casting

Because the target type (long) has all values in the range that are available in the source type (int)

2. Explicit casting: This is the process of assigning one entity to another by providing the transformation guidance. The compiler is specifically informed about the data transformation.

Example:
long longNumber = 700;
int number = (int) longNumber; //Explicit casting

Because the target type (int) does not have all the values in the range that are available in the source (long)
Java - Advantages and disadvantages of interfaces
Advantages and disadvantages of interfaces - Interfaces are mainly used to provide polymorphic behavior, Interfaces function to break up the complex..
What is Multithreading?
What is Multithreading? - A thread is one of the processes of an application. In multithreading, an OS allows different threads of an....
Types of Beans
Describe the types of Beans - Stateless Session Beans, Statefull Session Beans, Entity Beans......
Post your comment