E.The elements in the collection are guaranteed to be synchronized
98. Which two cannot directly cause a thread to stop executing? A.exiting from a synchronized block B.calling the wait method on an object C.calling the notify method on an object D.calling a read method on an InputStream object E.calling the setPriority method on a thread object
99. Given: public class SyncTest{ private int x; private int y; public void setX(int I){x=I;} public void setY(int I){y=I;} public synchronized void setXY(int I){setX(i);setY(i);} public synchronized boolean check(){return x != y;} } Under which conditions will check() return true when called from a different class? A.check() can never return true B.check()can return true when setXY is called by multiple threads C.check()can return true when multiple threads call setX and setY separately. D.check() can only return true if SynchTest is changed to allow x and y to be set separately.
100. class A implements Runnable{ int i; public void run(){ try{ Thread.sleep(50000); i=10; }catch(InterruptedException e){} } }
public class Test{ public static void main(String a[]){ try{ A a = new A(); Thread t = new Thread(a); t.start(); int j=a.i; }catch(Exception e){} } } Which statement at line 17 will ensure that j=10 at line 19? A.a.wait(); B.t.wait(); C.t.join(); D.t.yield(); E.t.notify(); F.a.notify(); G.t.interrupt();
101. 1.class EnclosingOne{ 2. public class InsideOne{} 3. } 4. public class InnerTest{ 5. public static void main(String []args){ 6. EnclosingOne eo=new EnclosingOne(); 7. //insert code here 8. } 9. } Which statement at line 7 constructs an instance of the inner class? A.InsideOne ei=eo.new InsideOne(); B.eo.InsideOne ei=eo.new InsideOne(); C.InsideOne ei=EnclosingOne.new InsideOne(); D.EnclosingOne. InsideOne ei=eo.new InsideOne();
102.Which method is an appropriate way to determine the cosine of 42 degrees? A.double d=Math.cos(42); B.double d=Math.cosine(42); C.double d=Math.cos(Math.toRadians(42)); D.double d=Math.cos(Math.toDegrees(42)); E.double d=Math.cosine(Math.toRadians(42));
103.Which is a method of the MouseMotionListener interface? A.public void mouseMoved(MouseEvent) B.public boolean mouseMoved(MouseEvent) C.public void mouseMoved(MouseMotionEvent) D.public boolean MouseMoved(MouseMotionEvent) E.public boolean mouseMoved(MouseMotionEvent)
104.Which statement is true for the class java.util.HashSet? A.The elements in the collection are ordered. B.The collection is guaranteed to be immutable. C.The elements in the collection are guaranteed to be unique. D.The elements in the collection are accessed using a unique key. E.The elements in the collection are guaranteed to be synchronized.
105. 1. public class Test{ 2. public static void add3(Integer i){ 3. int val=i.intvalue(); 4. val+=3; 5. i=new Integer(val); 6. } 7. 8. public static void main(String []args){ 9. Integer i=new Integer(0); 10. add3(i); 11. System.out.println(i.intvalue()); 12. } 13. } What is the result? A.Compilation will fail. B.The program prints “0”. C.The program prints “3”. D.Compilation will succeed but an exception will be thrown at line 3.
106.Given: 1. public class Test{ 2. public static void main(String []args){ 3. System.out.println(6^3); 4. } 5. } What is the output? Answer:
107.Which will declare a method that forces a subclass to implement it? A.public double methoda(); B.static void methoda(double d1){} C.public native double methoda(); D.abstract public void methoda(); E.protected void methoda(double d1){} |