não consegui chegar ao resultado:
qual letra será ???
Section 4: Concurrency > Objective 4.2 > Question 37
Given:
5. class Order2 implements Runnable {
6. public void run() {
7. for(int x = 0; x < 4; x++) {
8. try { Thread.sleep(100); } catch (Exception e) { }
9. System.out.print("r");
10. } }
11. public static void main(String [] args) {
12. Thread t = new Thread(new Order2());
13. t.start();
14. for(int x = 0; x < 4; x++) {
15. // insert code here
16. System.out.print("m");
17. } } }
Which, inserted at line 15, is most likely to produce the output rmrmrmrm?
A Thread.sleep(1);
B Thread.sleep(100);
C Thread.sleep(1000);
D try { Thread.sleep(1); } catch (Exception e) { }
E try { Thread.sleep(100); } catch (Exception e) { }
F try { Thread.sleep(1000); } catch (Exception e) { }
não entendi o resultado ???
Section 4: Concurrency > Objective 4.3 > Question 39
Given:
5. class NoGo implements Runnable {
6. private static int i;
7. public synchronized void run() {
8. if (i%10 != 0) { i++; }
9. for(int x=0; x<10; x++, i++)
10. { if (x == 4) Thread.yield(); }
11. }
12. public static void main(String [] args) {
13. NoGo n = new NoGo();
14. for(int x=0; x<101; x++) {
15. new Thread(n).start();
16. System.out.print(i + " ");
17. } } }
Which is true?
A The output can never contain the value 10.
B The output can never contain the value 30.
C The output can never contain the value 297.
D The output can never contain the value 820.
E Making the run method un-synchronized will not change the possible output.
outra duvida qtos tem ???
Section 5: OO Concepts > Objective 5.1 > Question 41
Given:
1. class TestFoo {
2. int x;
3. String y;
4. int getX() { return x; }
5. String getY() { return y; }
6. void setX(int x) {
7. int z = 7;
8. this.x = x;
9. }
10. }
How many modifiers must you add to encapsulate this class?
A 2
B 3
C 4
D 5
outra duvida ???
Section 5: OO Concepts > Objective 5.1 > Question 42
Given:
21. class Wheels {
22. private Bike bike;
23. void setBike(Bike b) { bike = b; }
24. }
25.
26. class Bike {
27. private Wheels [] wheels = new Wheels[5];
28. void setWheels(Wheels [] w) {
29. if( w.length == 2)
30. wheels = w;
31. }
32. }
Which is true?
A Compilation fails.
B These classes are NOT coupled.
C These classes are loosely coupled.
D These classes are tightly coupled.
E These classes are abstractly coupled.
mas uma que não entendi o que pedi>>???
Given:
1. class Book {
2. private final void read() { System.out.print("book "); }
3. }
4. class Page extends Book {
5. public static void main(String [] args) {
6. // insert code here
7. }
8. private final void read() { System.out.print("page "); }
9. }
And these three code fragments (x, y, z):
x. // just a comment
y. new Page().read();
z. new Book().read();
How many, inserted independently at line 6, allow the code to compile and run without exception?
A 0 B 1 C 2 D 3
o que quer dizer as 2 linhas abaixo o significado de <?> :
public static void takeCars(List<? extends Object> list) {}
public static void takeCars(List<?> list) { }
uma duvida referente ao Comparable
o retorno quando é zero vale apenas um objeto é isso ???
se voltar 1 ai tudo bem calcula em cima dos objetos adicionados essa é minha
duvida ???
class Stuff implements Comparable {
int x;
Stuff(int x) {
this.x = x;
}
public int compareTo(Object o) { return 0; }
}
public class Ex58 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TreeSet<Stuff> ts = new TreeSet<Stuff>();
ts.add(new Stuff(1));
ts.add(new Stuff(2));
ts.add(new Stuff(3));
System.out.println(ts.size());
}
}
não entendi porque saiu fora da ordem na hora
ka1 pois estava na ordem a,b,c
public static void main(String[] args) {
// TODO Auto-generated method stub
HashMap h = new HashMap();
h.put("a","aa"); h.put("b","bb"); h.put("c","cc");
Set ks = h.keySet();
Object [] ka1 = ks.toArray();
ks = new TreeSet(ks);
Object [] ka2 = ks.toArray();
System.out.println(Arrays.equals(ka1, ka2));
for(Object s:ka1){
System.out.println("ka1"+(String)s);
}
//System.out.println("ka1="+ka1.toString());
//System.out.println("ka2="+ka2.hashCode());
for(Object s:ka2){
System.out.println("ka2="+(String)s);
}
}
}
resultado:
false
ka1a
ka1c
ka1b
ka2a
ka2b
ka2c