Saturday, October 12, 2013

SCJP/OCJP IZO-851 Java Dumps - Four

Q1. Which three form part of correct array declarations? (Choose three)
A. public int a []
B. static int [] a
C. public [] int a
D. private int a [3]
E. private int [3] a []
F. public final int [] a
Answer: A, B, F
Q2. Given:
1. public class Foo {
2. public static void main(String[] args) {
3. try {
4. return;
5. } finally {
6. System.out.println( “Finally” );
7. }
8. }
9. }
What is the result?
A. Finally
B. Compilation fails.
C. The code runs with no output.
D. An exception is thrown at runtime.
Answer: A
Q3. Given:
ClassOne.java:
1. package com.abe.pkg1;
2. public class ClassOne {
3. private char var = ‘a’;
4. char getVar() { return var; }
5. }
ClassTest.java:
1. package com.abe.pkg2;
2. import com.abc.pkg1.ClassOne;
3. public class ClassTest extends ClassOne {
4. public static void main(String[] args) {
5. char a = new ClassOne().getVar();
6. char b = new ClassTest().getVar();
7. }
8. }
What is the result?
A. Compilation fails.
B. Compilation succeeds and no exceptions are thrown.
C. An exception is thrown at line 5 in ClassTest.java.
D. An exception is thrown at line 6 in ClassTest.java.
Answer: A
Q4. Given:
1. public class Alpha1 {
2. public static void main( String[] args ) {
3. boolean flag; int i=0;
5. do {
6. flag = false;
7. System.out.println( i++ );
8. flag = i < 10;
9. continue;
10. } while ( (flag)? true:false );
11. }
12. }
What is the result?
A. 000000000
B. 0123456789
C. Compilation fails.
D. The code runs with no output.
E. The code enters an infinite loop.
F. An exception is thrown at runtime.
Answer: B
Q5. Given:
1. package foo;
2.
3. import java.util.Vector;
4.
5. protected class MyVector Vector {
6. init i = 1;
7. public MyVector() {
8. i = 2;
9. }
10. }
11.
12. public class MyNewVector extends MyVector {
13. public MyNewVector() {
14. i = 4;
15. }
16. public static void main(String args[]) {
17. MyVector v = new MyNewVector();
18. }
19. }
What is the result?
A. Compilation succeeds.
B. Compilation fails because of an error at line 5.
C. Compilation fails because of an error at line 6.
D. Compilation fails because of an error at line 14.
E. Compilation fails because of an error at line 17.
Answer: B
Q6. Given:
1. class Super {
2. public Integer getLenght() { return new Integer(4); }
3. }
4.
5. public class Sub extends Super {
6. public Long GetLenght() { return new Long(5); }
7.
8. public static void main(String[] args) {
9. Super sooper = new Super();
10. Sub sub = new Sub();
11. System.out.println(
12. sooper.getLenght().toString() + “,” +
13. sub.getLenght().toString() );
14. }
15. }
What is the output?
A. 4,4
B. 4,5
C. 5,4
D. 5,5
E. Compilation fails.
Answer: A
Q7. Given:
1. public class Test {
2. public static String output =””;
3.
4. public static void foo(int i) {
5. try {
6. if(i==1) {
7. throw new Exception();
8. }
9. output += “1”;
10. }
11. catch(Exception e) {
12. output += “2”;
13. return;
14. }
15. finally {
16. output += “3”;
17. }
18. output += “4”;
19. }
20.
21. public static void main(String args[]) {
22. foo(0);
23. foo(1);
24.
25. }
26. }
What is the value of the variable output at line 23?
Answer: 13423
Q8. Given:
10. public Object m() {
11. Object o = new Float(3.14F);
12. Object [] oa = new Object[1];
13. oa[0] = o;
14. o = null;
15. return oa[0];
16. }
When is the Float object, created in line 11, eligible for garbage collection?
A. Just after line 13.
B. Just after line 14.
C. Never in this method.
D. Just after line 15 (that is, as the method returns).
Answer: B
Q9. Given:
1. class Base {
2. Base() { System.out.print(“Base”); }
3. }
4. public class Alpha extends Base {
5. public static void main( String[] args ) {
6. new Alpha();
7. new Base();
8. }
9. }
What is the result?
A. Base
B. BaseBase
C. Compilation fails.
D. The code runs with no output.
E. An exception is thrown at runtime.
Answer: B

No comments :

Post a Comment

iVTech Pageviews