DEV Community

Khushi Thakuri
Khushi Thakuri

Posted on

1 1

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)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay