Version: SE 8
User Program Communication
Object Oriented Programming
Type Casting in Java
Type casting is used to convert an object or variable of one type into another.
dataType variableName = (dataType) variableToConvert;
There are two casting directions: narrowing (larger to smaller type) and widening (smaller to larger type). Widening can be done automatically (for example, int to double), but narrowing must be done explicitly (like double to int).
double calculatedMark = 87.6; int finalGrade = (int)calculatedMark; //will return 87