Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

36. For each of the following programs that involve casting and Autoboxing, pred

ID: 669980 • Letter: 3

Question

36. For each of the following programs that involve casting and Autoboxing, predict the result of compiling and running the program. Potential answers include “there is a syntax error because…,” “there is a run-time error because…,” and “the output of the program would be …”

public class test3

   {

   public static void main (String[] args)

   }

       String sl;

       int il;

       Object ol;

       il = 35;

       ol = il;

       sl = (String) ol;

           System.out.println(sl.toLowerCase());

       }

   }

b. public class test4

   {

   public static void main (String[] args)

   {

       Integer Il;

       int il;

       Object ol;

       il = 35;

       ol = il;

       Il = (Integer) ol;

       System.out.println(Il); // This is an i and then an L.

   }

}

Explanation / Answer

public class test3

   {

   public static void main (String[] args)

   }

       String sl;

       int il;

       Object ol;

       il = 35;

       ol = il;

       sl = (String) ol;

           System.out.println(sl.toLowerCase());

       }

   }

There is a syntax error in this code. At the definition of main() function, you should open the brace and its closed instead. Even after that modification, it will return a runtime error, as you are trying to cast an integer value into a String type which is not possible.

b. public class test4

   {

   public static void main (String[] args)

   {

       Integer Il;

       int il;

       Object ol;

       il = 35;

       ol = il;

       Il = (Integer) ol;

       System.out.println(Il); // This is an i and then an L.

   }

}

Everything works fine with this code. It will be successfully compiled and executed. The output of this code will be 35.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote