Caros,
estou tentando fazer a classe para ver o resultado do teste abaixo
mas não estou conseguindo chegar ao resultado;
Given: t is a reference to a valid Thread object And the following valid run() method for t:
9. public void run() {
10. System.out.print("go ");
11. }
And:
18. t.start();
19. t.start();
20. t.run();
Which can be a result?
A go
B go go
C go go go
D go followed by an exception
E go go followed by an exception
F An exception is thrown with no other output.
o que estou tentando fazer para chegar ao resultado
public class Test extends Thread {
public void run() {
System.out.print("go ");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Test t = new Test();
t.start();
}
}
mais uma duvida abaixo resultado letra B
qdo criou o array a referencia do objeto ficou do Bird e do Parrots
e na hora do for da chamada talk foi pela referencia é isso ?
Given:
1. class Bird {
2. void talk() { System.out.print("chirp "); }
3. }
4. class Parrot2 extends Bird {
5. protected void talk() { System.out.print("hello "); }
6. public static void main(String [] args) {
7. Bird [] birds = {new Bird(), new Parrot2()};
8. for( Bird b : birds)
9. b.talk();
10. }
11. }
What is the result?
A chirp chirp
B chirp hello
C hello hello
D Compilation fails.
E An exception is thrown at runtime.
mais uma duvida abaixo
no if é verdade qdo se faz t.add(“one”) essa minha duvida ???
class AddStuff {
public static void main(String [] args) {
TreeSet<String> t = new TreeSet<String>();
if(t.add("one "))
if(t.add("two "))
if(t.add("one "))
t.add("two ");
for(String s : t)
System.out.print(s);
}
}
no codigo abaixo o metodo compareTo para qualquer valor que adicione
na lista para objeto Stuff vai voltar 1 como resultado …???
class Stuff implements Comparable {
int x;
Stuff(int x) { this.x = x; }
public int compareTo(Object o) { return 0; }
}
class AddStuff1 {
public static void main(String [] args) {
TreeSet<Stuff> ts = new TreeSet<Stuff>();
ts.add(new Stuff(1));
ts.add(new Stuff(2));
System.out.println(ts.size());
} }