Question

Java programming. 1) What, if anything, is wrong with the following Java code? void test(String x)...

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.

Homework Answers

Answer #1
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.



Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java code Problem 1. Create a Point class to hold x and y values for a...
Java code Problem 1. Create a Point class to hold x and y values for a point. Create methods show(), add() and subtract() to display the Point x and y values, and add and subtract point coordinates. Tip: Keep x and y separate in the calculation. Create another class Shape, which will form the basis of a set of shapes. The Shape class will contain default functions to calculate area and circumference of the shape, and provide the coordinates (Points)...
Java programming 1) Which among the choices is the following Java expression equivalent to? !((b !=...
Java programming 1) Which among the choices is the following Java expression equivalent to? !((b != 0) || (c <= 5)) Select one: a)       (b != 0) && (c <= 5) b)       (b == 0) && (c > 5) c)       !((b <> 0) && (c <= 5)) d)       (! (b = 0)) && (! (c > 5)) e)       (b == 0) && (c <= 5) 2) The scope of a variable is an important feature in Java, the following variable...
is there anything wrong with the solution. the question are from java course Write a main...
is there anything wrong with the solution. the question are from java course Write a main method that will request the user to enter Strings using a JOptionPane input dialog. The method should continue accepting strings until the user types “STOP”.       Then, using a JOptionPane message dialog, tell the user how many of the strings begin and end with a digit. Answer: import javax.swing.*; public class IsAllLetters {     public static void main(String[] args) {         String input;         int count =...
19) What will be the output of the following JavaScript code? for(var x = 1; x...
19) What will be the output of the following JavaScript code? for(var x = 1; x < 5; x++) console.log(x); a) 11111 b) 12345 c) 1234 d) 5555 20) What will be the output of the following JavaScript code? var x = 0 do{ console.log(x) }while(x > 0) a) 0 b) null c) 1 d) No output quiz 3 4) Which of the following is an entry point of ASP.NET Core application? a) Main method of Program class b) Configure...
The ability to read through Java™ code and predict the results, given specific inputs, is an...
The ability to read through Java™ code and predict the results, given specific inputs, is an extremely useful skill. For this assignment, you will be analyzing the Java™ code in the linked zip file, and predicting the results given specific input. Carefully read through the code line by line, then answer the following questions in a Microsoft® Word document: What is the output of the program as it is written? What would the output of the program be if you...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and packages: - variable names start with a lowercase character for the first word and uppercase for every other word - classes start with an uppercase character of every word - packages use only lowercase characters - methods start with a lowercase character for the first word and uppercase for every other word Java Programming COMP-228 Exercise #1: [5 marks] Write a Java application using...
The following code should print X is greater than 0. However, the code has errors. Fix...
The following code should print X is greater than 0. However, the code has errors. Fix the code so that it compiles and runs correctly. (Rewrite the program with all the fixes) public class Test1 { public static void main(String[] args) { int x = 3; if (x > 0 System.out.println("x is greater than 0") else System.out.println(x is less than or equal 0"); } } Must be in java and easy to understand grade 11 course
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
How can I alter this Java method so that I convert and then return every sentence...
How can I alter this Java method so that I convert and then return every sentence in the array of strings instead of just the first sentence? public static char[] charConvert ( String [] sentences ) { int totLength = sentences[0].length() + sentences[1].length() + sentences[2].length() + sentences[3].length() + sentences[4].length(); char [] letter = new char[totLength]; int x = 0; int y = 0;    while ( y < sentences[x].length() ) { switch ( sentences[x].charAt(y) ) { case 'a': case 'A':...
Download the attached .java file. Run it, become familiar with its processes. Your task is to...
Download the attached .java file. Run it, become familiar with its processes. Your task is to turn TemperatureConversion into GUI based program. it should, at the least, perform similar functions as their text output versions. The key factor to remember is that the workings should remain the same (some tweaks may be necessary) between text and GUI programs, while the means pf visual presentation and user interaction changes. You must properly document, comment, indent, space, and structure both programs. import...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT