Tuesday, November 29, 2011

What is the difference between an if statement and a switch statement?

The if statement is used to select among two alternatives. It uses a boolean expression todecide whichalternative should be executed. The switch statement is used to select among multiplealternatives. It usesan int expression to determine which alternative should be executed.:"if" statement can be used to compare about objects. for example: String compare to String. But for "switch" statement, it can only compare about int, byte,char, long, short, and enum:In if statement we can use relation operator such as(<,>,<=,>=) and also use boolean.
Category:Java Interview Questions

No comments:

Post a Comment