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?
A. assert value == null;
Given:11. public static void main(String[] args) {12. try {13. args = null;14. args[0] = "test";15. System.out.println(args[0]);16. } catch (Exception ex) {17. System.out.println("Exception");18. } catch (NullPointerException npe) {19. System.out.println("NullPointerException");20. }21. }
What is the result?
Click the Exhibit button.1. public class Test {2.3. public static void main(String [] args) {4. boolean assert = true;5. if(assert) {6. System.out.println(�assert is true�);7. }8. }9.10. }Given:javac -source 1.3 Test.java
A. The code will compile without changes.
Given two files:package pkg;public class Kit {public String glueIt(String a, String b) { return a+b; }}import pkg.*;class UseKit {public static void main(String[] args) {String s = new Kit().glueIt(args[1], args[2]);System.out.println(s);}}And the following sub-directory structure:test |--UseKit.class | com |--KitJar.jar
If the current directory is test, and the file pkg/Kit.class is in KitJar.jar, which command line will produce the output bc ? (Choose all that apply.)
Given:
11. public class Yikes {12.13. public static void go(Long n) {System.out.println("Long ");}14. public static void go(Short n) {System.out.println("Short ");}15. public static void go(int n) {System.out.println("int ");}16. public static void main(String [] args) {17. short y = 6;18. long z = 7;19. go(y);20. go(z);21. }22. }What is the result?
Given:11. static void test() {12. try {13. String x = null;14. System.out.print(x.toString() + " ");15. }16. finally { System.out.print("finally "); }17. }18. public static void main(String[] args) {19. try { test(); }20. catch (Exception ex) { System.out.print("exception "); }21. }
A. Inheritance represents an is-a relationship.
b = (Number instanceof s);
A. 420 is the output.
Click the Exhibit button.
10. public class Transfers {11. public static void main(String[] args) throws Exception {12. Record r1 = new Record();13. Record r2 = new Record();14. doTransfer(r1, r2, 5);15. doTransfer(r2, r1, 2);16. doTransfer(r1, r2, 1);17. // print the result18. System.out.println(�rl = � + r1.get() +�, r2=� + r2.get());19. }20. private static void doTransfer(21. final Record a, final Record b, final int amount) {22. Thread t = new Thread() {23. public void run() {24. new Clerk().transfer(a, b, amount);25. }26. };27. t.start();28. }29. }30. class Clerk {31. public synchronized void transfer(Record a, Record b, int amount){32. synchronized (a) {33. synchronized (b) {34. a.add(-amount);35. b.add(amount);36. }37. }38. }39. }40. class Record {41.int num=10;42. public int get() { return num; }43. public void add(int n) { num = num + n; }44. }If Transfers.main() is run, which three are true? (Choose three.)
Given:1. class Plant {2. String getName() { return "plant"; }3. Plant getType() { return this; }4. }5. class Flower extends Plant {6. // insert code here7. }8. class Tulip extends Flower { }
Which statement(s), inserted at line 6, will compile? (Choose all that apply.)
Given the default classpath: /foo
And this directory structure:
foo | test | xcom |--A.class |--B.javaAnd these two files:
package xcom;public class A { }package xcom;public class B extends A { }Which allows B.java to compile? (Choose all that apply.)
Given two files:1. class One {2. public static void main(String[] args) {3. int assert = 0;4. }5. }1. class Two {2. public static void main(String[] args) {3. assert(false);4. }5. }And the four command-line invocations:javac -source 1.3 One.javajavac -source 1.4 One.javajavac -source 1.3 Two.javajavac -source 1.4 Two.java
What is the result? (Choose all that apply.)
A. Only one compilation will succeed.
A. java test
Given:55. int [] x = {1, 2, 3, 4, 5};56. int y[] = x;57. System.out.println(y[2]);
Which statement is true?
Line 57 will print the value 2.