Created
November 29, 2008 14:31
-
-
Save jbgutierrez/30242 to your computer and use it in GitHub Desktop.
Pregunta de examen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class TestThread extends Thread | |
{ | |
public static void main(String[] args){ | |
new TestThread().start(); | |
new TestThread().start(); | |
} | |
public void run(){ | |
Vector<Safe> aList= new Vector<Safe>(); | |
for(Integer i = 0; i<3; i++) | |
aList.add((i % 2 == 0)?new Safe("abc"):new Safe("xyz")); | |
Vector<?extends NotSafe> oList = aList; | |
aList.add(new Safe("xyz")); | |
for(Object o:oList) | |
System.out.print(o.toString() + " "); | |
oList.add(null); //Linea 16 | |
int i = 1/0; //Linea 17 | |
} | |
} | |
class NotSafe | |
{ | |
}; | |
class Safe extends NotSafe | |
{ | |
private String str; | |
public Safe(String s){ | |
synchronized(this){ | |
str = new String(s); | |
if (str==s) | |
System.out.print(s + " "); | |
if (str.equals(s)) | |
System.out.print(s.toUpperCase() + " "); | |
System.out.print(" "); | |
} | |
} | |
public String toString(){ | |
return str; | |
} | |
}; | |
// a- El código no compila | |
// b- En el constructor de la clase Safe sólo se imprimen espacios en blanco | |
// c- No se puede determinar el orden de todos los System.out.print() pero sí de algunos; | |
// d- Se puede determinar el orden de la mitad de los System.out.print() | |
// e- Sin tener en cuenta las excepciones, se imprimen "abc" y "xyc" 12 veces cada una | |
// f- Sin tener en cuenta las excepciones, se imprimen "abc" y "xyc" 8 veces cada una | |
// g- Sin tener en cuenta las excepciones, se imprimen "abc" y "xyc" 4 veces cada una | |
// h- El bucle for del método run imprime "abc"s y "xyz"s. | |
// i- Se lanza una RuntimeException en la línea 16 | |
// j- Se lanza una RuntimeException en la línea 17 | |
// k- No se puede determinar el número de "abc" y "xyx" que se imprimen después del RuntimeException |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment