You are on page 1of 6

UNIVERSIDAD NACIONAL AUTONOMA DE MEXICO FACULTAD DE INGENIERIA NOTAS CERTIFICACIN JAVA SE6 EJERCICIOS PARTE 2 PREGUNTAS ESTILO CERTIFICACIN

Pregunta 21: Given: 1. class Dog { } 2. class Beagle extends Dog { } 3. 4. class Kennel { 5. public static void main(String [] arfs) { 6. Beagle b1 = new Beagle(); 7. Dog dog1 = new Dog(); 8. Dog dog2 = b1; 9. // insert code here 10. } 11. } Which, inserted at line 9, will compile? (Choose all that apply.) A. Beagle b2 = (Beagle) dog1; B. Beagle b3 = (Beagle) dog2; C. Beagle b4 = dog2; D. None of the above statements will compile Pregunta 22: Given: class Uber { static int y = 2; Uber(int x) { this(); y = y * 2; } Uber() { y++; } } class Minor extends Uber { Minor() { super(y); y = y + 3; } public static void main(String [] args) { new Minor(); System.out.println(y); } } What is the result? A. 6 B. 7 C. 8 D. 9 E. Compilation fails. F. An exception is thrown.

Ing. Jorge A. Rodrguez Campos

2013

1 de 6

1. Ejemplos / Ejercicios Pregunta 23: Given:

Certificacion Java SE 6 .

1. 2. 3. 4. 5. 6.

class Programmer { Programmer debug() { return this; } } class SCJP extends Programmer { // insert code here }

Which, inserted at line 5, will compile? (Choose all that apply.)

A. Programmer debug() { return this; } B. SCJP debug() { return this; } C. Object debug() { return this; } D. int debug() { return 1; } E. int debug(int x) { return 1; } F. Object debug(int x) { return this; }
Pregunta 24: Given:
1. class Ring { 2. final static int x2 = 7; 3. final static Integer x4 = 8; 4. public static void main(String[] args) { 5. Integer x1 = 5; 6. String s = "a"; 7. if(x1 < 9){ s += "b"}; 8. switch(x1) { 9. case 5: s += "c"; 10. case x2: s += "d"; 11. case x4: s += "e"; 12. } 13. System.out.println(s); 14. } 15. }

What is the result? A. abc B. abcde C. Compilation fails due only to an error on line 7. D. Compilation fails due only to an error on line 8. E. Compilation fails due only to an error on line 10. F. Compilation fails due only to an error on line 11. G. Compilation fails due to errors on multiple lines. Pregunta 25: Given:

Ing. Jorge A. Rodrguez Campos

2013

2 de 6

1. Ejemplos / Ejercicios
1. class Loopy { 2. public static void main(String[] args) { 3. int[] x = {7,6,5,4,3,2,1}; 4. // insert code here 5. System.out.print(y + " "); a 7. } 8. }

Certificacion Java SE 6 .

Which, inserted independently at line 4, compiles? (Choose all that apply.)

A. for(int B. for(x : C. int y = D. for(int E. for(int F. int y =

y : x) { int y) { 0; for(y : x) { y=0, z=0; z<x.length; z++) { y = x[z]; y=0, int z=0; z<x.length; z++) { y = x[z]; 0; for(int z=0; z<x.length; z++) { y = x[z];

Pregunta 26: Given:


1. 2. 3. 4. 5. class Zing { protected Hmpf h; } class Woop extends Zing { } class Hmpf { }

Which is true? (Choose all that apply.) A. Woop is-a Hmpf and has-a Zing. B. Zing is-a Woop and has-a Hmpf. C. Hmpf has-a Woop and Woop is-a Zing. D. Woop has-a Hmpf and Woop is-a Zing. E. Zing has-a Hmpf and Zing is-a Woop. Pregunta 27: Given:
1. 2. 3. 4. 5. 6. 7. 8. class Plant { String getName() { return "plant"; } Plant getType() { return this; } } class Flower extends Plant { // insert code here } class Tulip extends Flower { }

Which statement(s), inserted at line 6, will compile? (Choose all that apply.) A. Flower getType() { return this; } B. String getType() { return "this"; } C. Plant getType() { return this; } D. Tulip getType() { return new Tulip(); }

Pregunta 28: Given:

Ing. Jorge A. Rodrguez Campos

2013

3 de 6

1. Ejemplos / Ejercicios
3. class A { } 4. class B extends A { } 5. public class ComingThru { 6. static String s = "-"; 7. public static void main(String[] args) { 8. A[] aa = new A[2]; 9. B[] ba = new B[2]; 10. sifter(aa); 11. sifter(ba); 12. sifter(7); 13. System.out.println(s); 14. } 15. static void sifter(A[]... a2) { s += "1"; } 16. static void sifter(B[]... b1) { s += "2"; } 17. static void sifter(B[] b1) { s += "3"; } 18. static void sifter(Object o) { s += "4"; } 19. }

Certificacion Java SE 6 .

What is the result? A. -124 B. -134 C. -424 D. -434 E. -444 F. Compilation fails Pregunta 29: Given:

3. class Dog { 4. public void bark() { System.out.print("woof "); } 5. } 6. class Hound extends Dog { 7. public void sniff() { System.out.print("sniff "); } 8. public void bark() { System.out.print("howl "); } 9. } 10. public class DogShow { 11. public static void main(String[] args) { new DogShow().go(); } 12. void go() { 13. new Hound().bark(); 14. ((Dog) new Hound()).bark(); 15. ((Dog) new Hound()).sniff(); 16. } 17. }

What is the result? (Choose all that apply.) A. howl howl sniff B. howl woof sniff C. howl howl followed by an exception D. howl woof followed by an exception E. Compilation fails with an error at line 14 F. Compilation fails with an error at line 15 Pregunta 30: Given:

Ing. Jorge A. Rodrguez Campos

2013

4 de 6

1. Ejemplos / Ejercicios
class Plane { static String s = "-"; public static void main(String[] args) { new Plane().s1(); System.out.println(s); } void s1() { try { s2(); }catch (Exception e) { s += "c"; } } void s2() throws Exception { s3(); s += "2"; s3(); s += "2b"; } void s3() throws Exception { throw new Exception(); } }

Certificacion Java SE 6 .

What is the result? A. B. -c C. -c2 D. -2c E. -c22b F. -2c2b G. -2c2bc Pregunta 31: Given 1. public class Test245 { 2. public static void main (String [] args) { 3. try { 4. foo(); 5. } catch(Exception e) { 6. System.out.println(" Fee "); 7. } finally { 8. System.out.print(" Fi "); 9. } 10. } 11. 12. public static void foo() throws Exception { 13. try { 14. throw new Exception(); 15. } catch(Exception e) { 16. System.out.print(" Fo "); 17. } finally { 18. System.out.print(" Fum "); 19. } 20. } 21. } What is the result?

Ing. Jorge A. Rodrguez Campos

2013

5 de 6

1. Ejemplos / Ejercicios

Certificacion Java SE 6 .

A. B. C. D. E.

Fo Fum Fi Fo Fi Fum Fee Fi Fum Fee Fi Fo Fum Compilation fails

Pregunta 32: Which two statements are true? (Choose two.) A. B. C. D. E. F. You cannot throw a RuntimeException using throw An exception can be rethrown in a catch block. You must have a catch block for every try statement Catch blocks must always be ordered beginning with the least specific. You are allowed to create your own subclass of java.lang.RuntimeException. Once a try block begins to execute, if a exception ocurrs, a corresponding finally block will execute.

Ing. Jorge A. Rodrguez Campos

2013

6 de 6

You might also like