View Single Post
  #4  
Old 08-21-2007, 09:30 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 347
Venkat is on a distinguished road
Thumbs up 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
Reply With Quote