Você está na página 1de 8

1. Which one of the following methods keeps the Thread t in run state ? a) t.start() b) t.run() c) t.setRun( ) d) t.

stop e) when a thread is instantiated, it comes automatically into run state f) none
ANS : a

2.If the argument passed to the threads method setPriority( ) is not in the range of 1 to 10 (both inclusive), the method throws a) ArithmeticException b) IllegalArgumentException c) IllegalValueException d) none
ANS:c

3. sleep(50); The above statement of a thread implies that the thread will get the processortime a) any moment after 50 milliseconds b)exactly after 50 milliseconds c) even before 50 milliseconds if the processor is idle d) none ANS :b 4 A thread enters the dead state after completing its run method or when stop method is called. The stop method sends a ThreadDeath object on to the thread. The ThreadDeath is a subclass of _______. a) Exception b) Error c) both and depends on the source code d) none ANS:a What are the two parts of a value of type double? a)significant digits b)length c)exponent d)mode e)numerator ANS:a,c 6 After the following code fragment, what is the value in a? String s; int a; s = "Foolish boy."; a = s.indexOf("fool"); a)-1 ANS : a b) 0 c)4 d) random value

7 Suppose that you would like to create an instance of a new Map that has an iteration order that is the same as the iteration order of an existing instance of a Map. Which concrete implementation of the Map interface should be used for the new instance? a)TreeMap b)HashMap c) LinkedHashMap d)Answer depends on the implementation of existing instance

ANS: c 8. Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object? a)java.lang.String b)java.lang.double d)java.lang.character ANS : c 9. Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized? c)java.lang.StringBuffer

a)java.util.HashSet b) java.util.LinkedHashSet c)java.util.List d)java.Util.ArrayList ANS :d

10. Which interface does java.util.Hashtable implement? a)java.util.Map b) java.util.List d)java.Util.Collection ANS : a
11.

c)java.util.HashTable

public void test(int x) { int odd = 1; if(odd) /* Line 4 */ { System.out.println("odd"); } else { System.out.println("even");

} } a)Compilation Fails b)odd will be output c)even will be output d) odd will be output for odd values of x and for even values of x even will be output ANS: a 12.Which of the following java doesnt support? (a)Signed number (b)Unsigned number (c)Signed right shift (d)Unsigned right shift ANS :b

13. public class While { public void loop() { int x= 0; while ( 1 ) /* Line 6 */ { System.out.print("x plus one is " + (x + 1)); /* Line 8 */ } } } Which statement is true? a)There is a syntax error on line 1. b)There are syntax errors on lines 1 and 6. c)There are syntax errors on lines 1, 6, and 8. d)There is a syntax error on line 6. ANS:d

14) public class ArrayDemo { public static void main(String[] args) { if((int)Math.sqrt(2)==1)

System.out.println("equal(+)"); if((int)Math.sqrt(2)==-1) System.out.println("equal(-)"); } } What will be output of above program? (a) equal(+) (b) equal(-) (c) equal(+) equal(-) (d)Compiler error ANS:a

15)public class Overloading { short s=(2); Overloading(){ ++s; ++this.s; } Overloading(Overloading t){ ++t.s; ++this.s; } public static void main(String[] args) {

Overloading t1=new Overloading(); Overloading t2=new Overloading(t1); System.out.print(t2.s-t1.s); } } What will be output of above program? (a)0 (b)-1 (c)-2 (d)Compiler error ANS:c d)There is a syntax error on line 6.

16) try { int x = 0; int y = 5 / x; } catch (Exception e) { System.out.println("Exception"); } catch (ArithmeticException ae) { System.out.println(" Arithmetic Exception"); } System.out.println("finished"); a)finished c)Compilation fails. ANS:c b)Exception d)Arithmetic Exception

17)public class X { public static void main(String [] args) { try { badMethod(); System.out.print("A"); } catch (RuntimeException ex) /* Line 10 */ { System.out.print("B"); } catch (Exception ex1) { System.out.print("C"); } finally { System.out.print("D"); } System.out.print("E"); } public static void badMethod() { throw new RuntimeException(); } } a) BD b) BCD c).BDE d).BCDE Ans c

18)class Test { public static void main(String [] args) { int x=20; String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge"; System.out.println(sup); } }

a)small c)huge ANS:b

b)tiny d)Compilation fails

19) Which statement is true about a static nested class? You must have a reference to an instance of the enclosing class in order to a) instantiate it. b)It does not have access to nonstatic members of the enclosing class. c) It's variables and methods must be static. d)It must extend the enclosing class. ANS:b

20)Which three are methods of the Object class? 1. 2. 3. 4. 5. 6. 7. 8. notify(); notifyAll(); isInterrupted(); synchronized(); interrupt(); wait(long msecs); sleep(long msecs); yield(); b)2, 4, 5 d)2, 3, 4

a)1, 2, 4 c) 1, 2, 6 ANS:c

Você também pode gostar