1.

What is the pupose of using default in a switch statement?

Answer»

If there is no match for the expression with any case group in switch statement, the statements in the default part are executed.

For example:

{

switch(dy)

{

case 6: day = “Saturday”;

break;

case 7: day = “Sunday”;

break;

default: day = “Incorrect Day!

break;

}

System. out. print ln (day);

}

if the value of dy is other that 6 or 7 default statement will be executed.



Discussion

No Comment Found

Related InterviewSolutions