DEV Community

Khushi Thakuri
Khushi Thakuri

Posted on

casting in java

In simple language casting means changing one type of data type into another example changing double data type into int.
ie.

public class mk{
public static void main(String[] agrs){
double price = 55;
double finalPrice = 16.55;
System.out.println(finalPrice);
// our result will be 71.55 which is known as Implicit casting
// but now if we change our double type data type into int data type;
ie.
int p = 55;
int fp = p + (int)16.55;
System.out.println(fp);
//our result will be 71 only which is known as Explicit casting.

Top comments (0)