Menu
Topics Index
...
`

print statements by using Switch1462


If you need explanation Read this topic

If you need Answer Take test on this topic

print statements by using Switch1462
What will be the output of the following program?
public class DemoOnSwitch
{
    public static void main(String[] args)
    {
        int var = 12;
        switch ("var")
        {
            case "014" :
                System.out.print("Hello");
                break;
            case "12" :
                System.out.print("Hi");
            default :
                System.out.print("How r u?");
        }
    }
}

A. Hello
B. Hi
C. How r u?
D. HelloHow r u
E. Compilation Error or Runtime Error
Topic: switch Statement In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Answer is E...this program gives a compilation error as switch expression contains "var" which is the representation for a string where as var is declared as an int in the program

Posted by Shashanka Mogaliraju    2015-03-11 13:08:04


E

Posted by Induja Chinna    2015-03-11 13:09:37


E

Posted by Induja Chinna    2015-03-11 13:21:21


ans e. compilation error. switch expression must be of type byte , short , int or char .   switch provides a better multi-way branch than if-else-if ladder which executes multiple branches depending on the values of an expression.coming to this program var is assigned with 12.but here we used string "var" as expression. so compiler throws error

Posted by Maheshwari Natarajan    2015-03-11 18:33:46


This dose is now closed and the winners are Maheshwari Natarajan for the 'Popular Comment'. The 'lucky liker' is Mânïshå Mùlchåndânï. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-03-12 02:04:05


© meritcampus 2019

All Rights Reserved.

Open In App