Java programming.
1) What, if anything, is wrong with the following Java code?
void test(String x) { switch (x) { case 1: break; case 2: break; case 0: break; default: break; case 4: break; } }
Select one:
a)Each case section must end with a break statement.
b)The case label 0 must precede case label 1.
c)There is nothing wrong with the Java code.
d)The default label must be the last label in the switch statement.
e)The variable x does not have the right type for a switch expression.
2)
In order for the Java Virtual Machine (JVM) to run an application, what is required of a driver class? Which of the following statements is most true?
Select one:
a) The driver class needs to be compiled first and before any other classes.
b) The driver class requires a main method that is public so that the JVM can run a method without creating an instance of the class.
c) The driver class needs to be set to public so that it can be accessed by other classes within the package.
d) An instance of the driver class needs to be created first before the application can be run.
e) The driver class requires a main method that is static so that the JVM can run the method without creating an instance of the class.
Question 1: wrong with the following Java code is The default label must be the last label in the switch statement. So, answer is option d Answer: d)The default label must be the last label in the switch statement. Question 2: In order for the Java Virtual Machine (JVM) to run an application, The driver class requires a main method that is static so that the JVM can run the method without creating an instance of the class. So, answer is option e Answer: e) The driver class requires a main method that is static so that the JVM can run the method without creating an instance of the class.
Get Answers For Free
Most questions answered within 1 hours.