Type Casting

// Primitive Type Casting Order -- byte < short < int < long < float < double //


17. Program

//Find the O/P ? Compile Time Error or Compile Successfully

class R { static void test(int i) { System.out.println("test : " + i); } public static void main(String[] args) { byte b = 7; double d = 9.7; test(b); test((int)d); System.out.println("done"); } }

18. Program

//Find the O/P ? Compile Time Error or Compile Successfully

class S { static int test(double d) { return(int)d; } public static void main(String[] args) { long l = test(5.6); System.out.println(l); } }

19. Program

//Find the O/P ? Compile Time Error or Compile Successfully

class T { public static void main(String[] args) { double d = 11.2; float f = (float)d ; int i = (int) f; byte b = (byte)i; System.out.println("done"); } }

20. Program

//Find the O/P ? Compile Time Error or Compile Successfully

class U { public static void main(String[] args) { int i = 25; short s =(byte)i; System.out.println("Complete"); } }

21. Program

//Find the O/P ? Compile Time Error or Compile Successfully

class V { public static void main(String[] args) { double d = 10.90; long l = (int)d; System.out.println(l); System.out.println(d); System.out.println("Complete"); } }

23. Program

//Find the O/P ? Compile Time Error or Compile Successfully

class W { public static void main(String[] args) { double d = 11.90999; int i =(byte)(short)(int)d; System.out.println(i); System.out.println(d); System.out.println("Complete"); } }

24. Program

//Find the O/P ? Compile Time Error or Compile Successfully

class X { public static void main(String[] args) { double d =3.77; System.out.println(test((short)(byte)d)); System.out.println("Complete"); } static double test(int i) { return i; } }

Page....