Java 8 (Guía 2) - Examen
Java 8 (Guía 2) - Examen
a) Another Date
b) The code does not compile
c) A runtime exception is throw
d) 2018 APRIL 4
e) 2018 APRIL 30
f) 2018 MAY 10
a) 124
b) 1235
c) An uncaught exception is throw
d) The code does not compile
e) 1234
f) 12
g) 1245
3. What modifiers are assumed for all interface variables?(choose all that apply)
¿Qué modificadores se asumen para todas las variables de interfaz? (Elija todas las que
correspondan)
a) protected
b) private
c) public
d) abstract
e) final
f) static
Se supone que las variables de interfaz son públicas estáticas finales. A y B son incorrectas porque
las variables de la interfaz deben ser públicas: las interfaces son implementadas por las clases, no
heredadas por las interfaces. D es incorrecta porque las variables nunca pueden ser abstractas.
4. what is printed besides the stack trace caused by the NullPointException from line 16?
a) AECD
b) AEC
c) AE
d) AEBCD
e) No output appears other than the stack trace
5. what is the result of the following?
a) A
b) The code does not compile
c) B
d) An exception is thrown
e) C
6. what is the result of the following class?
a) match
b) Compiler error on line 11.
c) not match
d) Compiler error on line 10.
e) Compiler error on line 8.
f) A runtime exception is thrown.
7. what is the output of the following code snipper?
13: System.out.print(“a”);
14: try {
15: System.out.print(“b”);
16: throw new IllegalArgumentException();
17: } catch (Runtime exception e) {
18: System.out.print(“c”);
19: } finally {
20: System.out.print(“d”);
21: }
22: System.out.print(“e”);
a) the following code contains an infinite loop and does not terminate.
b) 11, 5
c) The code will not compile because of line 4.
d) 10, 6
e) The code will not compile because of line 3.
f) 10, 5
11. which exception will the following throw?
a) ClassCastException
b) NumberFormatException
c) ArrayIndexOutOfBoundsException
d) IllegalArgumentException
e) None of the above
12. what is the result of the following code snippet?
03: int m = 9, n = 1, x = 0;
04: while (m > n) {
05: m--;
06: n += 2;
07: x += m + n;
08: }
09: System.out.println(x);
a) 50
b) 23
c) 13
d) The code will not compile because of line 7.
e) 36
f) 11
13. what is the output of the following code snippet?
03: int x = 4;
04: long y = x * 4 – x++;
05: if (y < 10) System.out.println(“Too Low”);
06: else System.out.println(“Just Right”);
07: else System.out.println(“Too High”);
a) Just Right
b) Too High
c) The code will not compile because of line 7.
d) The code will not compile because of line 6.
e) Compiles but throws a NullPointerException.
f) Too Low
14. what is the result of the following program?
¿Qué modificadores se aplican implícitamente a todos los métodos de la interfaz? (elija todos
los que correspondan) o le gusten?
a) abstract
b) void
c) static
d) default
e) protected
f) public
Todos los métodos de la interfaz son implícitamente públicos, por lo que la opción f es correcta. La
opción E es incorrecta. Los métodos de la interfaz pueden declararse como estáticos o default,
pero nunca se añaden implícitamente. La B es incorrecta-void no es un modificador. A es
incorrecta, antes de Java 8 todos los métodos de la interfaz se asumían como abstractos.
Java 8 incluye métodos por default y estáticos para la interfaz, no puedes asumir que el
compilador aplicará implícitamente el modificador abstract a todos los métodos.
18. what is the result of the following code?
a) abbaaccc
b) bbaacca
c) bbaaaccc
d) The code does not compile.
e) An exception is thrown.
f) abbaccca
19. what is the result of the following code?
String s1 = “Java”;
String s2 = “Java”;
StringBuilder sb1 = new StringBuilder();
Sb1.append(“Ja”).append(“va”);
System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
System.out.println(sb.toString() == s1);
System.out.println(sb.toString().equals(s1));
a) 13
b) 6
c) 5
d) 4
e) 7
f) The code will not compile because the line 7.
21. What is the output of the following application?
a)Neither can be instantiated directly (Ninguno de los dos se puede instanciar directamente).
b)Both can contain public static final variables (Ambos pueden contener variables finales
estáticas públicas).
c)All methods within them are assumed to be abstract (Se asume que todos los métodos dentro de
ellos son abstractos).
d)Both can contain default methods (Ambos pueden contener métodos default).
e)Both can be extended using the extend keyword (Ambos se pueden extender usando la
palabra clave extend).
g)Both can contain static methods (Ambos pueden contener métodos estaticos).
C es incorrecto, porque una clase abstracta puede contener métodos concretos. Desde Java 8, las
interfaces también pueden contener métodos concretos en forma de métodos estáticos o por
default.
Aunque se supone que todas las variables de las interfaces son públicas estáticas finales, las clases
abstractas también pueden contenerlas, por lo que B es correcta.
Tanto las clases abstractas como las interfaces pueden extenderse con la palabra clave extends,
por lo que E es correcto.
Sólo las interfaces pueden contener métodos por default, por lo que D es incorrecta.
Tanto las clases abstractas como las interfaces pueden contener métodos estáticos, por lo que G
es correcta.
Tanto las clases abstractas como las interfaces requieren una subclase concreta para ser
instanciadas, por lo que A es correcta.
a) s->s.isEmpty()
b) String s->s.isEmpty()
c) s->{s.isEmpty()}
d) s->{return s.isEmpty();}
e) s->{ s.isEmpty();}
f) (String s)-> s.isEmpty()
A la opción B le faltan los paréntesis alrededor de la lista de parámetros. Los paréntesis son
opcionales para un solo parámetro con un tipo inferido.
25. What is the output of the following code snippet
a. ArrayIndexOutOfBoundsException
b. ExceptionInInitializerError
c. java.io.IOException
d. NullPointerException
e. NumberFormatException
3: long y=x*(long)x;
4: x=-1;
5: return y;
6: }
8: int value = 9;
10: System.out.println(value);
11: }}
a. -1
b. 9
c. 81
d. Compiler error on line 9.
e. Compiler error on a different line.
What is the result of the following code?
list.add(array[0]);
list.add(array[2]);
list.set(1, array[1]);
list.remove(0);
System.out.println(list);
a. [8]
b. [9]
c. Something like [Ljava.lang.String;@160bc7c0
d. An exception is thrown.
e. The code does not compile.