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

6. Given the following Animation class: public class Animation public void play

ID: 3665549 • Letter: 6

Question

6. Given the following Animation class: public class Animation public void play I don't know how!"); and the following application: public class Bad public static void main(String arguments int if arguments length 0) II arguments null)) println( arguments[0]) System ou System.out.println(arguments[arguments.length]); i 1; Animation play(); a. Put an N next to all of the statements that will not compile (i.e., next to all of the statements that have syntactic defects) in the Bad class. b. Put an X next to all of the statements that will compile but will definitely generate an exception at run-time e., ults that will definitely cause a failure at run-time) c. Put a next to all of that statements that will compile and may, depending on the parameters, generate an exception at run-time.

Explanation / Answer

public class Bad
{
public static void main(String arguments[])
{
int i;
  
if((arguments.length > 0) || arguments !=null)
{
/* The below line will generate an ArrayIndexOutOfBound exception if no command line argument is passed //otherwise no exception is generated Because if no argument is passed then arguments.length will be 0 but //it will not be null so the if condition will be fulfilled and  the code in if block will be executed in both the //cases, and when there is no argument argument[0] will not be present thus an exception.*/

System.out.println(arguments[0]); ? // Exception based on arguments passed
System.out.println(arguments.length);
}
  
i=1;
j=2; N //This will not compile because j is not declared
  
++i;
  
// The below line will not compile because Animation is a class and not an object so we cannot only call //methods using clas names except for static method. Inorder to make this line valid we have to change play //method static

Animation.play(); N   
}
}

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