Sei sulla pagina 1di 2

Analizar y Responder UNO - POO1

1 *. Dado: E) Compilation fails


class Alpha { F) An exception is thrown at run time.
String getType() { return "alpha"; } ............................................
}
class Beta extends Alpha { 4. Dado:
String getType() { return "beta"; }
} public class Shape {
class Gamma extends Beta { private String color;
String getType() { return "gamma"; }
public static void main(String[] args) { public Shape(String color) {
Gamma g1 = new Alpha(); System.out.print("Shape");
Gamma g2 = new Beta(); this.color = color;
System.out.println(g1.getType() + " " }
+ g2.getType());
} public static void main(String[] args) {
} new Rectangle();
}
Devuelve: }
A) alpha beta
B) beta beta class Rectangle extends Shape {
C) gamma gamma public Rectangle() {
D) alpha alpha super("Blue");
E) Compilation fails. System.out.print("Rectangle");
.......................................... }
}
2 *. Dado:
public class MyLoop { ¿Cuál es el resultado?
public static void main(String[] args) {
A. ShapeRectangle
String[] sa = {"tom ", "jerry "}; B. RectangleShape
C. Rectangle
for(int x = 0; x < 3; x++) { D. Error de compilación línea 3
E. Error de compilación línea 12
for(String s: sa) {
System.out.print(x + " " + s); ...........................................
if( x == 1) break;
} 5. Dado:
}
} public class Parent {
} public Parent(int x) {
System.out.print("A");
Devuelve: }
A) 0 tom 0 jerry 1 tom }
B) 0 tom 0 jerry 1 tom 1 jerry
C) 0 tom 0 jerry 2 tom 2 jerry class Child extends Parent {
D) 0 tom 0 jerry 1 tom 2 tom 2 jerry public Child(int x) {
E) 0 tom 0 jerry 1 tom 1 jerry 2 tom 2 jerry System.out.print("B");
F) Compilation fails. }
..........................................
public Child() {
3 *. Dados: this(123);
class Feline { System.out.print("C");
public String type = "f "; }
public Feline() { }
System.out.print("feline ");
} ¿Cuál es el resultado de la siguiente sentencia?
} new Child();

public class Cougar extends Feline { A. ABC


B. ACB
public Cougar() { C. AB
System.out.print("cougar "); D. AC
} E. Error de compilación
public static void main(String[] args) {
new Cougar().go();
} 6. Dados:
void go() { public class MyStuff {
type = "c ";
System.out.print(this.type + super.type); MyStuff(String n) { name = n; }
} String name;
}
public static void main(String[] args) {
Devuelve: MyStuff m1 = new MyStuff("guitar");
A) cougar c c MyStuff m2 = new MyStuff("tv");
B) cougar c f System.out.println(m2.equals(m1));
C) feline cougar c c }
D) feline cougar c f

* Extraido de: https://annatheannoying.wordpress.com/2015/03/11/java-7-certification-exam-sample-questions/


Analizar y Responder UNO - POO1

public boolean equals(Object o) {


MyStuff m = (MyStuff) o;
if(m.name != null)
return true;

return false;
}
}

Devuelve:
A) La salida es true y MyStuff cumple el contrato
Object.equals().
B) La salida es false y MyStuff cumple el contrato
Object.equals().
C) La salida es true pero MyStuff NO cumple el
contrato Object.equals().
D) La salida es false pero MyStuff NO cumple con
el contrato Object.equals().
E) Compilation fails

7. Dado:

public class Batman {


int squares = 81;

public static void main(String[] args) {


new Batman().go();
}

void go() {
incr(++squares);
System.out.println(squares);
}

void incr(int squares) {


squares += 10;
}

¿Cuál es el resultado?

A. 81
B. 82
C. 91
D. 92
E. Compilation fails.
F. An exception is thrown at runtime
...........................................

8. Dados:

abstract class C1 {
public C1() { System.out.print(1); }
}
class C2 extends C1 {
public C2() { System.out.print(2); }
}
class C3 extends C2 {
public C3() { System.out.println(3); }
}
public class Ctest {
public static void main(String[] a) { new C3(); }
}

¿Cuál es el resultado?

A. 3
B. 23
C. 32
D. 123
E. 321
F. Compilation fails.
G. An exception is thrown at runtime.
...........................................

* Extraido de: https://annatheannoying.wordpress.com/2015/03/11/java-7-certification-exam-sample-questions/

Potrebbero piacerti anche