ejercicios para certificación java se 6

Upload: gabriel-miranda

Post on 04-Jun-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Ejercicios para certificacin JAVA SE 6

    1/6

    Ing. Jorge A. Rodrguez Campos 2013 1 de 6

    UNIVERSIDAD NACIONAL AUTONOMA DE MEXICO

    FACULTAD DE INGENIERIA

    NOTAS CERTIFICACIN JAVA SE6

    EJERCICIOS PARTE 2PREGUNTAS 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. 7C. 8

    D. 9

    E. Compilation fails.

    F. An exception is thrown.

  • 8/13/2019 Ejercicios para certificacin JAVA SE 6

    2/6

    1. Ejemplos / Ejercicios Certificacion Java SE 6 .

    Ing. Jorge A. Rodrguez Campos 2013 2 de 6

    Pregunta 23: Given:

    1. class Programmer {

    2. Programmer debug() { return this; }

    3. }

    4. class SCJP extends Programmer {5. // insert code here

    6. }

    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:

  • 8/13/2019 Ejercicios para certificacin JAVA SE 6

    3/6

    1. Ejemplos / Ejercicios Certificacion Java SE 6 .

    Ing. Jorge A. Rodrguez Campos 2013 3 de 6

    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. }

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

    A. for(int y : x) {

    B. for(x : int y) {

    C. int y = 0; for(y : x) {D. for(int y=0, z=0; z

  • 8/13/2019 Ejercicios para certificacin JAVA SE 6

    4/6

    1. Ejemplos / Ejercicios Certificacion Java SE 6 .

    Ing. Jorge A. Rodrguez Campos 2013 4 de 6

    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. }

    What is the result?

    A. -124B. -134

    C. -424

    D. -434E. -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 sniffC. howl howlfollowed by an exception

    D. howl wooffollowed by an exception

    E. Compilation fails with an error at line 14

    F. Compilation fails with an error at line 15

    Pregunta 30: Given:

  • 8/13/2019 Ejercicios para certificacin JAVA SE 6

    5/6

    1. Ejemplos / Ejercicios Certificacion Java SE 6 .

    Ing. Jorge A. Rodrguez Campos 2013 5 de 6

    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();

    }

    }

    What is the result?

    A. -

    B. -c

    C. -c2D. -2c

    E. -c22b

    F. -2c2bG. -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?

  • 8/13/2019 Ejercicios para certificacin JAVA SE 6

    6/6

    1. Ejemplos / Ejercicios Certificacion Java SE 6 .

    Ing. Jorge A. Rodrguez Campos 2013 6 de 6

    A.Fo Fum Fi

    B.Fo Fi Fum

    C.Fee Fi Fum

    D.Fee Fi Fo Fum

    E.Compilation fails

    Pregunta 32: Which two statements are true? (Choose two.)

    A. You cannot throw a RuntimeException using throw

    B. An exception can be rethrown in a catch block.

    C. You must have a catch block for every try statement

    D. Catch blocks must always be ordered beginning with the least specific.

    E. You are allowed to create your own subclass of java.lang.RuntimeException.

    F. Once a try block begins to execute, if a exception ocurrs, a corresponding finally block will execute.