QUESTION 11 Given that Triangle implements Runnable, and: 31. void go() throws Exception { 32. Thread t = new Thread(new Triangle()); 33. t.start(); 34. for(int x = 1; x
QUESTION 10 Given: public class NamedCounter { private final String name; private int count; public NamedCounter(String name) { this.name = name; } public String getName() { return name; } public void increment() { count++; } public int getCount() { return count; } public void reset() { count = 0; } } Which three changes should be made to adapt this class to be used safely by multiple threads? (..
QUESTION 9 Given: 1. public class Threads3 implements Runnable { 2. public void run() { 3. System.out.print("running"); 4. } 5. public static void main(String[] args) { 6. Thread t = new Thread(new Threads3()); 7. t.run(); 8. t.run(); 9. t.start(); 10. } 11. } What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. The code executes and prints running. D. The code exec..
QUESTION 8 Given: 1. public class TestOne { 2. public static void main (String[] args) throws Exception { 3. Thread.sleep(3000); 4. System.out.println("sleep"); 5. } 6. } What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. The code executes normally and prints sleep. D. The code executes normally, but nothing is printed. Solution : C
QUESTION 7 Click the Exhibit button. 10. interface Foo{ 11. int bar(); 12. } 13. 14. public class Beta { 15. 16. class A implements Foo { 17. public int bar(){ return 1; } 18. } 19. 20. public int fubar(Foo foo){ return foo.bar(); } 21. 22. public void testFoo(){ 23. 24. class A implements Foo{ 25. public int bar(){return 2;} 26. } 27. 28. System.out.println(fubar(new A())); 29. } 30. 31. public..
QUESTION 6 Given: 11. public interface A111 { 12. String s = "yo"; 13. public void method1(); 14. } 15. 16. 17. interface B {} 18. 19. 20. interface C extends A111, B { 21. public void method1(); 22. public void method1(int x); 23. } What is the result? A. Compilation succeeds. B. Compilation fails due to multiple errors. C. Compilation fails due to an error only on line 20. D. Compilation fails..