Home Tutorial Java Scjp Part2 SCJP Module-2 Question-7

 
 

SCJP Module-2 Question-7
Posted on: July 7, 2010 at 12:00 AM
Advertisement
The given program below is from switch case in core Java for preparation of SCJP examinination

Which one is correct option :

1.  public class Example7 {
2.  public static void main(String args[]) {
3 . Example7 e7 = new Example7();
4.  int b = ? ;
5.  e7.Movie(b);
6.  }
7.  public void Movie(int q) {
8.  switch (q) {
9.  case 1:
10. System.out.print("me ");
11. case 2:
12 .System.out.print("myself ");
13 .break;
14. case 3:
15. System.out.print("Irene ");
16. default:
17. System.out.print("Movie");
18. }}}

Which input-output option is correct :

(1).a = 4, Output = " Movie"

(2)a=0, Output="me myself"

(3)a=3,Output="Irene Movie"

(4)a= 1, Output = " me"

Answer :

(1) & (3)

Explanation :

Since break is in between case1 & case 2 , the case switch will continue until it meets to break or end of the program. Input 0 & 1 produce -'Movie' & 'me myself' respectively.

Advertisement

Related Tags for SCJP Module-2 Question-7:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 7, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com