Menu
Question Index
...

What will be the output of the following program?

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


Value = 2
Value = 4
Value = 6
Value = 8
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Methods - Parameter Passing And Scope

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App