Type Casting in JAVA

 

Type Casting in JAVA


• General form: (targetType) value

• Examples:

• 1) integer value will be reduced module bytes

range:

int i;

byte b = (byte) i;


• 2) floating-point value will be truncated to integer

value:

float f;

int i = (int) f;



Simple Java Program

A class to display a simple message:


class MyProgram

{

public static void main(String[] args)

{


System.out.println(“First Java program.");

}

}



Post a Comment (0)
Previous Post Next Post