adplus-dvertising
frame-decoration

Question

What will be the output of the program?

public class SwitchTest 
{  
    public static void main(String[] args) 
    {
        System.out.println("value =" + switchIt(4)); 
    } 
    public static int switchIt(int x) 
    {
        int j = 1;  
        switch (x) 
        { 
            case l: j++; 
            case 2: j++;  
            case 3: j++; 
            case 4: j++; 
            case 5: j++; 
            default: j++; 
            } 
        return j + x;  
    } 
}

a.

value = 2

b.

value = 4

c.

value = 6

d.

value = 8

Answer: (d).value = 8

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What will be the output of the program?

Similar Questions

Discover Related MCQs

Q. Decrement operator '--' decreases the value of variable by what number?

Q. What is/are highest order precedence operator(s) in Java?

Q. The && and || operators

Q. Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?

Q. Select from among the following character escape code which is not available in Java.

Q. With x = 0, which of the following are legal lines of Java code for changing the value of x to 1?

1. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;

Q. Which of these is returned by "greater than", "less than" and "equal to" operators?

Q. Which of the following operators can operate on a boolean variable?

Q. Which of these statements is correct?

Q. What is the order of precedence (highest to lowest) of following operators?

1. &
2. ^
3. ?:

Q. _______ is not a flow control statement in Java.

Q. The break statement causes an exit from ______ loop.

Q. Which of the following is an iteration statement?

Q. An Arithmetic expression in Java involves which Operators or Operations?

Q. Choose the Compound Assignment Arithmetic Operators in Java below.

Q. Which is the arithmetic operator in Java that gives the Remainder of Division?

Q. Arithmetic operators +, -, /, * and % have which Associativity?

Q. Between Postfix and Prefix arithmetic operators in Java, which operators have more priority?

Q. Among Postfix Decrement and Prefix Incrementoperators in Java, which operator has less priority?

Q. Increment and Decrement arithmetic operators in Java has which Associativity?