JAVA DUMPS 4(SCJP)

QUESTION NO: 16


 

Given:

1. public class Delta {

2. static boolean foo(char c) {

3. System.out.print(c);

4. return true;

5. }

6. public static void main( String[] argv ) {

7. int i =0;

8. for ( foo('A'); foo('B')&&(i<2); foo('C')){

9. i++ ;

10. foo('D');

12. }

13. }

14. }


 

What is the result?

A. ABDCBDCB

B. ABCDABCD

C. Compilation fails.

D. An exception is thrown at runtime.


 

Answer: A


 

QUESTION NO: 17


 

Given:

1. public class Test{

2. public static void main( String[] argv ){

3. // insert statement here

4. }

5. }


 

Which statement, inserted at line 3, produces the following output?

Exception in thread "main" java.lang.AssertionError: true

at Test.main(Test.java:3)

A. assert true;

B. assert false;

C. assert false : true;

D. assert false == true;

E. assert false: false;


 

Answer: C


 

QUESTION NO: 18


 

Given:

1. public class ArrayTest {

2. public static void main(String[] args) {

3. float fl[], f2[];

4. fl = new float[10];

5. f2 = f1;

6. System.out.println("f2[0]= " + f2[0]);

7. }

8. }


 

What is the result?


 

A. It prints f2[0] = 0.0.

B. It prints f2[0] = NaN.

C. An error at line 5 causes compile to fail.

D. An error at line 6 causes compile to fail.

E. An error at line 6 causes an expectation at runtime.


 

Answer: A


 

QUESTION NO: 19


 

Given:

1. public class Test {

2. public int aMethod() {

3. static int i = 0;

4. i++;

5. return i;

6. }

7. public static void main (String args[]) {

8. Test test = new Test();

9. test.aMethod();

10. int j = test.aMethod();

11. System.out.println(j);

12. }

13. }


 

What is the result?

A. 0

B. 1

C. 2

D. Compilation fails.


 

Answer: D


 

QUESTION NO: 20


 

Given:

1. class Super {

2. public float getNum() { return 3.0f; }

3. }

4.

5. public class Sub extends Super {

6.

7. }


 

Which method, placed at line6, causes compilation to fail?

A. public void getNum() { }

B. public void getNum(double d) { }

C. public float getNum() { return 4.0f; }

D. public double getNum(float d) { return 4.0d; }


 

Answer: A


 

QUESTION NO: 21


 

Given:

11. boolean bool = true;

12. if(bool = false) {

13. System.out.println("a");

14. } else if (bool) {

15. System.out.println("c");

16. } else if (!bool) {

17. System.out.println("c");

18. } else {

19. System.out.println("d");

20. }


 

What is the result?

A. a

B. b

C. c

D. d

E. Compilation fails.


 

Answer: E

QUESTION NO: 22


 

Which statement is true?


 

A. catch(X x) can catch subclasses of X.

B. The Error class us a RuntimeException.

C. Any statement that can throw an Error must be enclosed in a try block.

D. Any statement that can throw an Exception must be enclosed in a try block.

E. Any statement that can throw a RuntimeException must be enclosed in a try block.


 

Answer: A

2 comments:

Anonymous said...

Answer C is correct for Question 21

Anonymous said...

Yes the correct answer for Q21 is C. the code compile fine, in the first logic comparation the false value is assigned to the bool var and in this case this is correct only for boolean type

Post a Comment