Search Placementyogi.com
 

Difficult Java If Else And Switch Objective Questions and Answers

  :: Topics ::

1

What is the output of the following program?

class SwitchControl 
{
	public static void main(String[] args) 
	{
		double d=10;
		switch(d)
		{
			case 10 : System.out.println("Case 10!");
					 
			case 20 :  System.out.println("Case 20!");
					 
		    default :  System.out.println("Default Case");
		}
	}
}
A.

Case 10!

B.

Case 10!

Case 20!

Default Case

C.

Compilation Error

D.

RunTime Error

See Answer & Explanation Lets Discuss
Correct answer is : C
Explanation

switch expects an integer as the expression and when it encounters double it throws the error:

C:\java_practice\src\control\SwitchControl.java:6: error: possible loss of precision

                switch(d)

                       ^

  required: int

  found:    double

1 error

 
 

Banner to LogicGuns.com

Hide Page Information

Java Difficult If Else And Switch Objective Questions and Answers for Written Round Interview

Here you can find Java Difficult If Else And Switch Objective Questions with answers and explanation. We have a vast collection of Objective Questions on Difficult If Else And Switch in Java that will help you a lot!

Why learn Java Difficult If Else And Switch?

Difficult If Else And Switch are an integral part of Java and many Objective Questions in the written round are asked from this topic.In this section you can learn and practice Java Difficult If Else And Switch (Objective Questions with Answers) to improve your skills in order to face the interview and clear campus and off-campus selection of TCS, Infosys, Wipro etc.

Where can I get Java Difficult If Else And Switch Objective Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved Java Difficult If Else And Switch Objective Questions and answers with explanation. Fully solved examples with detailed answer description, explanation are given and it would be easy to understand.Though we do not have pdf file for Java Difficult If Else And Switch, We have quiz Objective Questions with answers to help you test yourself..

\n

Where can I get Java Difficult If Else And Switch Interview Objective Questions and Answers (objective type, multiple choice)?

Here you can find objective type Java Difficult If Else And Switch Objective Questions and answers for interview and entrance examination.Multiple Answers and true or false type Objective Questions are also provided.

How to solve Java Difficult If Else And Switch problems?

You can easily solve all kind of Objective Questions based on Java Difficult If Else And Switch by practicing the exercises (including shortcut Difficult If Else And Switch to solve problems) given below.