Tuesday 6 September 2011

SCJP Questions 51-60

                                   PREVIOUS                       NEXT
Question 51
Click the Exhibit button.
11. public class Bootchy {
12. int bootch;
13. String snootch;
14.
15. public Bootchy() {
16. this(”snootchy”);
17. System.out.print(”first “);
18. }
19.
20. public Bootchy(String snootch) {
21. this(420, “snootchy”);
22. System.out.print(”second “);
23. }
24.
25. public Bootchy(int bootch, String snootch) {
26. this.bootch = bootch;
27. this.snootch = snootch;
28. System.out.print(”third “);
29. }
30.
31. public static void main(String[] args) {
32. Bootchy b = new Bootchy();
33. System.out.print(b.snootch +“ “ + b.bootch);
34. }
35. }
What is the result?
A. snootchy 420 third second first
B. snootchy 420 first second third
C. first second third snootchy 420
D. third second first siiootchy 420
E. third first second snootchy 420
F. first second first third snootchy 420
Answer: D

Question 52
Given:
11. public class Test {
12. public enum Dogs {collie, harrier, shepherd};
13. public static void main(String [] args) {
14. Dogs myDog = Dogs.shepherd;
15. switch (myDog) {
16. case collie:
17. System.out.print(”collie “);
18. case default:
19. System.out.print(”retriever “);
20. case harrier:
21. System.out.print(”harrier “);
22. }
23. }
24. }
‘What is the result?
A. harrier
B. shepherd
C. retriever
D. Compilation fails.
E. retriever harrier
F. An exception is thrown at runtime.
Answer: D

Question 53
Given:
12. public class Test {
13. public enum Dogs {collie, harrier};
14. public static void main(String [] args) {
15. Dogs myDog = Dogs.collie;
16. switch (myDog) {
17. case collie:
18. System.out.print(”collie “);
19. case harrier:
20. System.out.print(”harrier “);
21. }
22. }
23. }
What is the result?
A. collie
B. harrier
C. Compilation fails.
D. collie harrier
E. An exception is thrown at runtime.
Answer: D

Question 54
Given:
11. public void testIfA() {
12. if(testIfB(”True”)) {
13. System.out.println(”True”);
14. } else {
15. System.out.println(”Not true”);
16. }
17. }
18. public Boolean testIfB(String str) {
19. return Boolean.valueOf(str);
20. }
What is the result when method testIfA is invoked?
A. True
B. Not true
C. An exception is thrown at runtime.
D. Compilation fails because of an error at line 12.
E. Compilation fails because of an error at line 19.
Answer: A

Question 55
Given:
11. public static void main(String[] args) {
12. Integer i = uew Integer(1) + new Integer(2);
13. switch(i) {
14. case 3: System.out.println(”three”); break;
15. default: System.out.println(”other”); break;
16. }
17. }
‘What is the result?
A. three
B. other
C. An exception is thrown at runtime.
D. Compilation fails because of an error on line 12.
E. Compilation fails because of an error on line 13.
F. Compilation fails because of an error on line 15.
Answer: A

Question 56
Given:
11. public static void main(String[] args) {
12. String str = “null’;
13. if (str == null) {
14. System.out.println(”null”);
15. } else (str.length() == 0) {
16. System.out.println(”zero”);
17. } else {
18. System.out.println(”some”);
19. }
20. }
‘What is the result?
A. null
B. zero
C. some
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: D

Question 57
Given:
11. Float pi = new Float(3.14f);
12.if(pi>3) {
13. System.out.print(”pi is bigger than 3. “);
14. }
15. else {
16. System.out.print(”pi is not bigger than 3. “);
17. }
18. finally {
19. System.out.println(”Have a nice day.”);
20. }
‘What is the result?
A. Compilation fails.
B. pi is bigger than 3.
C. An exception occurs at runtime.
D. pi is bigger than 3. Have a nice day.
E. pi is not bigger than 3. Have a nice day.
Answer: A

Question 58
Given:
10.int x=0;
11.int y 10;
12. do {
l3. y--;
14. ++x;
15. } while (x < 5);
16. System.out.print(x + “,“ + y);
What is the result?
A. 5,6
B. 5,5
C. 6,5
D. 6,6
Answer: B

Question 59
Given:
25.intx=12;
26. while (x < 10) {
27. x--;
28. }
29. System.out.print(x);
What is the result?
A. 0
B. 10
C. 12
D. Line 29 will never be reached.
Answer: C

Question 60
Given:
35. int x= 10;
36. do {
37. x--;
38. } while(x< 10);
How many times will line 37 be executed?
A. ten times
B. zero times
C. one to me times
D. more than ten times
Answer: D

                                          PREVIOUS                       NEXT

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...