Powered by Blogger.

Write a Java Prorgam Using Casting | Type Casting in Java

Casting means assigning a value of one type to a variable of another type.

 public class CastTest{
 public static void main(String[ ]args){
 long bigValue = 99L;
 int smallValue = (int)bigValue; // Casting
 System.out.println(smallValue);
 smallValue = 50;
 bigValue = smallValue; // Auto Casting
 System.out.println(bigValue);
  }
 }

Type Casting in Java:

Assigning a value of one type to a variable of another type is known as Type Casting.

Example :-

int x = 10;
byte y = (byte)x;



1 comment: