JavaVER.01-12

Page 80

Exam F QUESTION 1 Which two code fragments will execute the method doStuff() in a separate thread? (Choose two.) A. new Thread() { public void }; B. new Thread() { public void }; C. new Thread() { public void }.run(); D. new Thread() { public void }.start(); E. new Thread(new public void }).run(); F. new Thread(new public void }).start();

run() { doStuff(); }

start() { doStuff(); }

start() { doStuff(); }

run() { doStuff(); } Runnable() { run() { doStuff(); } Runnable() { run() { doStuff(); }

Answer: DF Section: All Explanation/Reference:

QUESTION 2 Given: public class Person { private String name; public Person(String name) { this.name = name; } public boolean equals(Object o) { if ( ! ( o instanceof Person) ) return false; Person p = (Person) o; return p.name.equals(this.name); } } Which statement is true? A. B. C. D.

Compilation fails because the hashCode method is not overridden. A HashSet could contain multiple Person objects with the same name. All Person objects will have the same hash code because the hashCode method is not overridden. If a HashSet contains more than one Person object with name="Fred", then removing another Person, also with name="Fred", will remove them all.

Answer: B Section: All Explanation/Reference:

QUESTION 3 Given:


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.