Type Casting and Type Cast Operator.

Q29. What do you mean by type casting? What is type cast operator?

Ans. The explicit conversion of an operand to a specific type is called Type Casting.

Type casting in Java is done  as shown below:

(type) expression

where type is a valid Java data type to which the conversion is to be done. For example, to make sure that the expression (x+y/2) evaluates to type float, write it as:

(float) (x+y/2)

casts ate often considered as operators. As an operator, a cast is unary and has the same precedence as any other unary operator.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: