1.
Given: 11. Runnable r = new Runnable() { 12. public void run() { 13. System.out.print("Cat"); 14. } 15. }; 16. Thread t = new Thread(r) { 17. public void run() { 18. System.out.print("Dog"); 19. } 20. }; 21. t.start(); What is the result?
2.
Given: 23. int z = 5; 24. 25. public void stuff1(int x) { 26. assert (x > 0); 27. switch(x) { 28. case 2: x = 3; 29. default: assert false; } } 30. 31. private void stuff2(int y) { assert (y < 0); } 32. 33. private void stuff3() { assert (stuff4()); } 34. 35. private boolean stuff4() { z = 6; return false; } Which statement is true?
3.
Given a method that must ensure that its parameter is not null: 11. public void someMethod(Object value) { 12. // check for null value ... 20. System.out.println(value.getClass()); 21. } What, inserted at line 12, is the appropriate way to handle a null value?
4.
Given: 11. public class Test { 12. public enum Dogs {collie, harrier, shepherd}; 13. public static void main(String [] args) { 14. Dogs myDog = Dogs.shepherd; 15. switch (myDog) { 16. case collie: 17. System.out.print("collie "); 18. case default: 19. System.out.print("retriever "); 20. case harrier: 21. System.out.print("harrier "); 22. } 23. } 24. } What is the result?
5.
Given: d is a valid, non-null Date object df is a valid, non-null DateFormat object set to the current locale What outputs the current locale's country name and the appropriate version of d's date?
6.
Given: 11. static void test() throws Error { 12. if (true) throw new AssertionError(); 13. System.out.print("test "); 14. } 15. public static void main(String[] args) { 16. try { test(); } 17. catch (Exception ex) { System.out.print("exception "); } 18. System.out.print("end "); 19. } What is the result?
7.
Given: 10. abstract class A { 11. abstract void a1(); 12. void a2() { } 13. } 14. class B extends A { 15. void a1() { } 16. void a2() { } 17. } 18. class C extends B { void c1() { } } and: A x = new B(); C y = new C(); A z = new C(); What are four valid examples of polymorphic method calls? (Choose four.)
8.
Given: 10. public class SuperCalc { 11. protected static int multiply(int a, int b) { return a * b;} 12. } and: 20. public class SubCalc extends SuperCalc{ 21. public static int multiply(int a, int b) { 22. int c = super.multiply(a, b); 23. return c; 24. } 25. } and: 30. SubCalc sc = new SubCalc (); 31. System.out.println(sc.multiply(3,4)); 32. System.out.println(SubCalc.multiply(2,2)); What is the result?
9.
Given: 11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B extends A { 15. void process() { System.out.println("B "); } 16. } 17. public static void main(String[] args) { 18. A a = new B(); 19.
10.
Given: 12. String csv = "Sue,5,true,3"; 13. Scanner scanner = new Scanner( csv ); 14. scanner.useDelimiter(","); 15. int age = scanner.nextInt(); What is the result?