Re: Java/J2EE interview Questions hey, Define casting? What are the different types of Casting?
Changing the type of the value from one type to other is termed as casting. For instancelook at the below code snippet in which we are trying to cast integer value to double datatype.
int i;
double d;
i = 10;
d = i; // we are trying to assign a int value to double
There are two types of casting explicit and implicit. To explicitly cast an expression prefixthe expression with type name as shown in the code snippet below.
Button mybtn = (Button) (myVector.elementAt(9));
In some situations JAVA runtime changes the type of an expression with out performinga cast. For instance in the below code snippet my inventory object is type casted andstored as type Object.
myVectorSales.add(objInventory);
__________________ Venkat knowledge is Power |