FileDocCategorySizeDatePackage
CastNeeded.javaAPI DocExample354Sat Mar 06 15:58:52 GMT 2004None

CastNeeded.java

/** Casting Demo. */
public class CastNeeded {
	//+
	public static void main(String[] argv) {
		int i;
		double j = 2.75;
		i = j;			// EXPECT COMPILE ERROR
		i = (int)j;		// with cast; i gets 2
		System.out.println("i =" + i);
		byte b;
		b = i;			// EXPECT COMPILE ERROR
		b = (byte)i;	// with cast, i gets 2
		System.out.println("b =" + b);
	}
	//-
}