Java Quiz-2

110 Questions | Attempts: 136
Please wait...
Question 1 / 111
🏆 Rank #--
Score 0/100

1. Given: int x = 0; int y = 10; do { y--; ++x; } while (x < 5); System.out.print(x + "," + y); What is the result? 5,6 5,5 6,5 6,6

Submit
Please wait...
About This Quiz
Java Quiz-2 - Quiz

. Created by Rahul and Anurag

2.

What first name or nickname would you like us to use?

You may optionally provide this to label your report, leaderboard, or certificate.

2. Consider the following code and choose the correct output: public class Test{ public static void main(String[] args) { int x = 0; int y = 10; do { y--; ++x; } while (x < 5); System.out.print(x + "," + y); } } 5,6 5,5 6,5 6,6

Submit

3. Given: class Atom { Atom() { System.out.print("atom "); } } class Rock extends Atom { Rock(String type) { System.out.print(type); } } public class Mountain extends Rock { Mountain() { super("granite "); new Rock("granite "); } public static void main(String[] a) { new Mountain(); } } What is the result? Compilation fails. granite granite atom granite granite atom granite atom granite

Submit

4. Consider the following code and choose the correct output: class Test{ public static void main(String args[]){ int num=3; switch(num){ case 1: case 3: case 4: { System.out.println("bat man"); } case 2: case 5: { System.out.println("spider man"); }break; } }} bat man Compilation error bat man spider man spider man

Submit

5. What is the output : class One{ public static void main(String[] args) { int a=100; if(a>10) System.out.println("M.S.Dhoni"); else if(a>20) System.out.println("Sachin"); else if(a>30) System.out.println("Virat Kohli");} } M.S.Dhoni M.S.Dhoni Sachin Virat Kohli Virat Kohli all of these

Submit

6. Which of the following loop bodies DOES compute the product from 1 to 10 like (1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10)? int s = 1; for (int i = 1; i <= 10; i++) { <What to put here?> } s += i * i; s++;  s = s + s * i; s *= i;

Submit

7. Given: double height = 5.5; if(height-- >= 5.0) System.out.print("tall "); if(--height >= 4.0) System.out.print("average "); if(height-- >= 3.0) System.out.print("short "); else System.out.print("very short "); } What would be the Result? tall tall short short very short

Submit

8. Switch(x) { default: System.out.println("Hello"); } Which of the following are acceptable types for x? 1.byte 2.long 3.char 4.float 5.Short 6.Long 1 ,3 and 5 2 and 4 3 and 5 4 and 6

Submit

9. What will be the output of the program? int x = 3; int y = 1; if (x = y) /* Line 3 */ { System.out.println("x =" + x); } x = 1 x = 3 Compilation fails. The code runs with no output.

Submit

10. Consider the following code and choose the correct output: class Test{ public static void main(String args[]){ int num=3; switch(num){ default :{ System.out.print("default");} case 1: case 3: case 4: { System.out.println("apple"); break;} case 2: case 5: { System.out.println("black berry"); }break; } }} apple default apple compilation error default

Submit

11. Examine the following code: int count = 1; while ( ___________ ) { System.out.print( count + " " ); count = count + 1; } System.out.println( ); What condition should be used so that the code prints:1 2 3 4 5 6 7 8 count < 9 count+1 <= 8 count < 8 count != 8

Submit

12. Given: public class Batman { int squares = 81; public static void main(String[] args) { new Batman().go(); } void go() { incr(++squares); System.out.println(squares); } void incr(int squares) { squares += 10; } } What is the result? 81 82 91 92

Submit

13. Given: int a = 5; int b = 5; int c = 5; if (a > 3) if (b > 4) if (c > 5) c += 1; else c += 2; else c += 3; c += 4; What is the value of variable c after executing the following code? 3 5 7 11

Submit

14. Which of the following statements about arrays is syntactically wrong? Person[] p = new Person[5]; Person p[5]; Person[] p []; Person p[][] = new Person[2][];

Submit

15. Import java.util.SortedSet; import java.util.TreeSet; public class Main { public static void main(String[] args) { TreeSet<String> tSet = new TreeSet<String>(); tSet.add("1"); tSet.add("2"); tSet.add("3"); tSet.add("4"); tSet.add("5"); SortedSet sortedSet =_____________("3"); System.out.println("Head Set Contains : " + sortedSet); } } What is the missing method in the code to get the head set of the tree set? tSet.headSet tset.headset headSet HeadSet

Submit

16. 11. double input = 314159.26; 12. NumberFormat nf = NumberFormat.getInstance(Locale.ITALIAN); 13. String b; 14. //insert code here Which code, inserted at line 14, sets the value of b to 314.159,26? b = nf.parse( input ); b = nf.format( input ); b = nf.equals( input ); b =nf.parseObje ct( input );

Submit

17. Consider the following code and choose the correct option: class Test{ public static void main(String ar[]){ TreeMap<Integer,String> tree = new TreeMap<Integer,String>(); tree.put(1, "one"); tree.put(2, "two"); tree.put(3, "three"); tree.put(4,"Four"); System.out.println(tree.higherKey(2)); System.out.println(tree.ceilingKey(2)); System.out.println(tree.floorKey(1)); System.out.println(tree.lowerKey(1)); }} 3 2 1 null   3 2 1 1 2 2 1 1 4 2 1 1

Submit

18. What does the following code fragment write to the monitor? int sum = 21; if ( sum != 20 ) System.out.print("You win "); else System.out.print("You lose "); System.out.println("the prize."); What does the code fragment prints? You win the prize You lose the prize. You win You lose

Submit

19. Class AutoBox { public static void main(String args[]) { int i = 10; Integer iOb = 100; i = iOb; System.out.println(i + " " + iOb); } } whether this code work properly, if so what would be the result? No,Compilation error No, Runtime error Yes, 10, 100 Yes, 100,100

Submit

20. What is the output : class try1{ public static void main(String[] args) { int x=1; if(x--) System.out.println("good"); else System.out.println("bad"); } } good bad compile error   run time error

Submit

21. Which one do you like?Which collection implementation is suitable for maintaining an ordered sequence of objects,when objects are frequently inserted in and removed from the middle of the sequence? TreeMap HashSet Vector LinkedList

Submit

22. Consider the following code and choose the correct option: int i = l, j = -1; switch (i) { case 0, 1: j = 1; case 2: j = 2; default: j = 0; }System.out.println("j = " + j); j = -1 j = 0 j = 1 Compilation fails

Submit

23. Public class SwitchTest { public static void main(String[] args) { System.out.println("value =" + switchIt(4)); } public static int switchIt(int x) { int j = 1; switch (x) { case 1: j++; case 2: j++; case 3: j++; case 4: j++; case 5: j++; default: j++; } return j + x; } } What will be the output of the program? value = 8 value = 2 value = 4 value = 6

Submit

24. Class s implements Runnable { int x, y; public void run() { for(int i = 0; i < 1000; i++) synchronized(this) { x = 12; y = 12; } System.out.print(x + " " + y + " "); } public static void main(String args[]) { s run = new s(); Thread t1 = new Thread(run); Thread t2 = new Thread(run); t1.start(); t2.start(); } } What is the output? DeadLock Compilation Error Cannot determine output. prints 12 12 12 12

Submit

25. What will be the output of following code? import java.util.*; class I { public static void main (String[] args) { Object i = new ArrayList().iterator(); System.out.print((i instanceof List)+","); System.out.print((i instanceof Iterator)+","); System.out.print(i instanceof ListIterator); } } Prints: false, false, false Prints: false, false, true Prints: false, true, false Prints: false, true, true

Submit

26. What are the thing to be placed to complete the code? class Wrap { public static void main(String args[]) { _______________ iOb = ___________ Integer(100); int i = iOb.intValue(); System.out.println(i + " " + iOb); // displays 100 100 } } int, int Integer, new Integer, int int, Integer

Submit

27. What will be the result of attempting to compile and run the following class? Public class IFTest{ public static void main(String[] args){ int i=10; if(i==10) if(i<10) System.out.println("a"); else System.out.println("b"); }} The code will fail to compile because the syntax of the if statement is incorrect The code will fail to compile because the compiler will not be able to determine which if statement the else clause belongs to The code will compile correctly and display the letter a,when run The code will compile correctly and display the letter b,when run

Submit

28. What is the output of the following code : class try1{ public static void main(String[] args) { System.out.println("good"); while(false){ System.out.println("morning"); } } } good good morning morning …. compiler error runtime error

Submit

29. Consider the following code and choose the correct output: class Test{ public static void main(String args[]){ int num='b'; switch(num){ default :{ System.out.print("default");} case 100 : case 'b' : case 'c' : { System.out.println("brownie"); break;} case 200: case 'e': { System.out.println("pastry"); }break; } }} brownie default brownie compilation error default

Submit

30. Given: Float pi = new Float(3.14f); if (pi > 3) { System.out.print("pi is bigger than 3. "); } else { System.out.print("pi is not bigger than 3. "); } finally { System.out.println("Have a nice day."); } What is the result? Compilation fails. pi is bigger than 3. An exception occurs at runtime. pi is bigger than 3. Have a nice day.

Submit

31. Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ String hexa = "0XFF"; int number = Integer.decode(hexa); System.out.println(number); }} Compilation error 1515 255 Compiles but error at run time

Submit

32. Class Trial{ public static void main(String[] args){ try{ System.out.println("One"); int y = 2 / 0; System.out.println("Two"); } catch(RuntimeException ex){ System.out.println("Catch"); } finally{ System.out.println("Finally"); } } } One Two Catch Finally One Catch One Catch Finally One Two Catch

Submit

33. Given: public class Barn { public static void main(String[] args) { new Barn().go("hi", 1); new Barn().go("hi", "world", 2); } public void go(String... y, int x) { System.out.print(y[y.length - 1] + " "); } } What is the result? hi hi hi world world world Compilation fails.

Submit

34. Which four can be thrown using the throw statement? 1.Error 2.Event 3.Object 4.Throwable 5.Exception 6.RuntimeException 1, 2, 3 and 4 2, 3, 4 and 5 1, 4, 5 and 6 2, 4, 5 and 6

Submit

35. Given: public void go() { String o = ""; z: for(int x = 0; x < 3; x++) { for(int y = 0; y < 2; y++) { if(x==1) break; if(x==2 && y==1) break z; o = o + x + y; } } System.out.println(o); } What is the result when the go() method is invoked? 0 0 0 0 0 1 0 0 0 1 2 0 0 0 0 1 2 0 21

Submit

36. What will be the output of the program? public class Switch2 { final static short x = 2; public static int y = 0; public static void main(String [] args) { for (int z=0; z < 3; z++) { switch (z) { case y: System.out.print("0 "); /* Line 11 */ case x-1: System.out.print("1 "); /* Line 12 */ case x: System.out.print("2 "); /* Line 13 */ } } } } 0 1 2 0 1 2 1 2 2 Compilation fails at line 11 Compilation fails at line 12.

Submit

37. What is the output : class Test{ public static void main(String[] args) { int a=5,b=10,c=1; if(a>c){ System.out.println("success"); } else{ break; } } } success runtime error compiler error none of the listed options

Submit

38. Which of the following statements is TRUE regarding a Java loop? A continue statement doesn't transfer control to the test statement of the for loop An overflow error can only occur in a loop A loop may have multiple exit points If a variable of type int overflows during the execution of a loop, it will cause an exception

Submit

39. Given: class X implements Runnable { public static void main(String args[]) { /* Some code */ } public void run() {} } Which of the following line of code is suitable to start a thread ? X run = new X(); Thread t = new Thread(run); t.start(); Thread t = new Thread(X); Thread t = new Thread(); x.run(); Thread t = new Thread(X); t.start();

Submit

40. Given: int n = 10; switch(n) { case 10: n = n + 1; case 15: n = n + 2; case 20: n = n + 3; case 25: n = n + 4; case 30: n = n + 5; } System.out.println(n); What is the value of 'n' after executing the following code? 23 32 25 Compilation Error

Submit

41. Public void foo( boolean a, boolean b) { if( a ) { System.out.println("A"); /* Line 5 */ } else if(a && b) /* Line 7 */ { System.out.println( "A && B"); } else /* Line 11 */ { if ( !b ) { System.out.println( "notB") ; } else { System.out.println( "ELSE" ) ; } } } What would be the result? If a is true and b is false then the output is "notB" If a is true and b is true then the output is "A && B" If a is false and b is false then the output is "ELSE" If a is false and b is true then the output is "ELSE"

Submit

42. 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? There is a syntax error on line 1 There are syntax errors on lines 1 and 6 There are syntax errors on lines 1, 6, and 8 There is a syntax error on line 6

Submit

43. Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ int x=034; int y=12; int ans=x+y; System.out.println(ans); }} 40 46 compilation error Compiles but error at run time

Submit

44. What is the value of 'n' after executing the following code? int n = 10; int p = n + 5; int q = p - 10; int r = 2 * (p - q); switch(n) { case p: n = n + 1; case q: n = n + 2; case r: n = n + 3; default: n = n + 4; } 14 28 Compilation Error 10

Submit

45. Which digit,and in what order,will be printed when the following program is run? Public class MyClass { public static void main(String[] args) { int k=0; try { int i=5/k; } catch(ArithmeticException e) { System.out.println("1"); } catch(RuntimeException e) { System.out.println("2"); return; } catch(Exception e) { System.out.println("3"); } finally{ System.out.println("4"); } System.out.println("5"); } } The program will only print 5 The program will only print 1 and 4 in order The program will only print 1,2 and 4 in order The program will only print 1 ,4 and 5 in order

Submit

46. Consider the following code and choose the correct output: class Test{ public static void main(String args[]){ int a=5; if(a=3){ System.out.print("Three");}else{ System.out.print("Five");}}} Compilation error Three Five Compiles but no output

Submit

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

Submit

48. Which of the following is a checked exception? Arithmetic Exception IOException NullPointerEx ception ArrayIndexOu tOfBoundsEx ception

Submit

49. Given: 11. class A { 12. public void process() { System.out.print("A,"); } 13. class B extends A { 14. public void process() throws IOException { 15. super.process(); 16. System.out.print("B,"); 17. throw new IOException(); 18. } 19. public static void main(String[] args) { 20. try { new B().process(); } 21. catch (IOException e) { System.out.println("Exception"); } 22. } What is the result? Exception A,B,Exception Compilation fails because of an error in line 20. Compilation fails because of an error in line 14.

Submit

50. What is wrong with the following code? Class MyException extends Exception{} public class Test{ public void foo() { try { bar(); } finally { baz(); } catch(MyException e) {} } public void bar() throws MyException { throw new MyException(); } public void baz() throws RuntimeException { throw new RuntimeException(); } } Since the method foo() does not catch the exception generated by the method baz(),it must declare the RuntimeExce ption in a throws clause A try block cannot be followed by both a catch and a finally block An empty catch block is not allowed A catch block cannot follow a finally block

Submit

51. What will be the output of following code? TreeSet map = new TreeSet(); map.add("one"); map.add("two"); map.add("three"); map.add("four"); map.add("one"); Iterator it = map.iterator(); while (it.hasNext() ) { System.out.print( it.next() + " " ); } one two three four four three two one four one  three two one two three four one

Submit

52. What will be the output of the program? public class RTExcept { public static void throwit () { System.out.print("throwit "); throw new RuntimeException(); } public static void main(String [] args) { try { System.out.print("hello "); throwit(); } catch (Exception re ) { System.out.print("caught "); } finally { System.out.print("finally "); } System.out.println("after "); } } hello throwit caught Compilation fails hello throwit RuntimeExce ption caught after hello throwit caught finally after

Submit

53. Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ Long data=23; System.out.println(data); }}  23 Compilation error Compiles but error at run time None of the listed options

Submit

54. Class X implements Runnable { public static void main(String args[]) { /* Missing code? */ } public void run() {} } Which of the following line of code is suitable to start a thread ? Thread t = new Thread(X); Thread t = new Thread(X); t.start(); X run = new X(); Thread t = new Thread(run); t.start(); Thread t = new Thread(); x.run();

Submit

55. Which of the following statements is true? catch(X x) can catch subclasses of X where X is a subclass of Exception. The Error class is a RuntimeExce ption. Any statement that can throw an Error must be enclosed in a try block. Any statement that can throw an Exception must be enclosed in a try block.

Submit

56. Given: public static void test(String str) { int check = 4; if (check = str.length()) { System.out.print(str.charAt(check -= 1) +", "); } else { System.out.print(str.charAt(0) + ", "); } } and the invocation: test("four"); test("tee"); test("to"); What is the result? r, t, t, r, e, o, Compilation fails. An exception is thrown at runtime.

Submit

57. If a method is capable of causing an exception that it does not handle, it must specify this behavior using throws so that callers of the method can guard themselves against such Exception 

Submit

58. Which statement is true? The notifyAll() method must be called from a synchronized context To call sleep(), a thread must own the lock on the object The notify() method is defined in class java.lang.Thr ead The notify() method causes a thread to immediately release its locks.

Submit

59. Which of the following allows a programmer to destroy an object x? x.delete() x.finalize() Runtime.getR untime().gc() Only the garbage collection system can destroy an object.

Submit

60. Which of the following methods are static? start() join() yield() sleep()

Submit

61. Which of the following statements are true regarding wrapper classes? (Choose TWO) String is a wrapper class Double has a compareTo() method Character has a intValue() method Byte extends Number

Submit

62. Which of these statements are true? HashTable is a sub class of Dictionary ArrayList is a sub class of Vector LinkedList is a subclass of ArrayList Stack is a subclass of Vector

Submit

63. Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ int l=7; Long L = (Long)l; System.out.println(L); }} 7 Compilation error Compiles but error at run time None of the listed options

Submit

64. What will happen when you attempt to compile and run the following code? public class Bground extends Thread{ public static void main(String argv[]){ Bground b = new Bground(); b.run(); } public void start(){ for (int i = 0; i <10; i++){ System.out.println("Value of i = " + i); } } } A compile time error indicating that no run method is defined for the Thread class A run time error indicating that no run method is defined for the Thread class Clean compile and at run time the values 0 to 9 are printed out Clean compile but no output at runtime

Submit

65. Class Trial{ public static void main(String[] args){ try{ System.out.println("Java is portable"); } } } Java is portable We cannot have a try block without a catch block We cannot have a try block block without a catch / finally block Nothing is diaplayed

Submit

66. Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ Long l=0l; System.out.println(l.equals(0));}} Compilation error true false 1 

Submit

67. Consider the following code and choose the correct option: class Test{ static void test() throws RuntimeException { try { System.out.print("test "); throw new RuntimeException(); } catch (Exception ex) { System.out.print("exception "); } } public static void main(String[] args) { try { test(); } catch (RuntimeException ex) { System.out.print("runtime "); } System.out.print("end"); } } test end test runtime end test exception runtime end test exception end

Submit

68. Public class Test { public static void main(String [] args) { int x = 5; boolean b1 = true; boolean b2 = false; if ((x == 4) && !b2 ) System.out.print("1 "); System.out.print("2 "); if ((b2 = true) && b1 ) System.out.print("3 "); } } What is the result? 2 3 2 3 1 2 3

Submit

69. Which statement is true? A static method cannot be synchronized . If a class has synchronized code, multiple threads can still access the nonsynchroni zed code. Variables can be protected from concurrent access problems by marking them with the synchronized keyword. When a thread sleeps, it releases its locks

Submit

70. Int I = 0; outer: while (true) { I++; inner: for (int j = 0; j < 10; j++) { I += j; if (j == 3) continue inner; break outer; } continue outer; } System.out.println(I); What will be thr result? 3 2 4 1

Submit

71. Class PropagateException{ public static void main(String[] args){ try{ method(); System.out.println("method() called"); } catch(ArithmeticException ex){ System.out.println("Arithmetic Exception"); } catch(RuntimeException re){ System.out.println("Runtime Exception"); }} static void method(){ int y = 2 / 0; }} consider the code above & select the proper output from the options. Arithmetic Exception Runtime Exception Arithmetic Exception Runtime Exception compiltion error

Submit

72. A) Checked Exception must be explicity caught or propagated to the calling method B) If runtime system can not find an appropriate method to handle the exception, then the runtime system terminates and uses the default exception handler. Only A is TRUE Only B is TRUE Bothe A and B is TRUE Both A and B is FALSE

Submit

73. Public class RTExcept { public static void throwit () { System.out.print("throwit "); throw new RuntimeException(); } public static void main(String [] args) { try { System.out.print("hello "); throwit(); } catch (Exception re ) { System.out.print("caught "); } finally { System.out.print("finally "); } System.out.println("after "); } } hello throwit caught finally after hello throwit caught hello throwit RuntimeExce ption caught after Compilation fails

Submit

74. Class Trial{ public static void main(String[] args){ try{ System.out.println("Try Block"); } finally{ System.out.println("Finally Block"); } } } Try Block Try Block Finally Block   Finally Block Finally Block Try Block

Submit

75. Which statement is true? A. A class's finalize() method CANNOT be invoked explicitly. B. super.finalize() is called implicitly by any overriding finalize() method. C. The finalize() method for a given object is called no more than once by the garbage collector. D. The order in which finalize() is called on two objects is based on the order in which the two objects became finalizable. A B C D

Submit

76. What is the keyword to use when the access of a method has to be restricted to only one thread at a time volatile synchronized final private

Submit

77. Public static void parse(String str) { try { float f = Float.parseFloat(str); } catch (NumberFormatException nfe) { f = 0; } finally { System.out.println(f); } } public static void main(String[] args) { parse("invalid"); }  0 Compilation fails A ParseExcepti on is thrown by the parse method at runtime. A NumberForm atException is thrown by the parse method at runtime.

Submit

78. The exceptions for which the compiler doesn't enforce the handle or declare rule Checked exceptions Unchecked exceptions Exception all of these

Submit

79. Given: public class ExceptionTest { class TestException extends Exception {} public void runTest() throws TestException {} public void test() /* Line X */ { runTest(); } } At Line X, which code is necessary to make the code compile? No code is necessary throws Exception throw Exception throws RuntimeExce ption

Submit

80. Given two programs: 1. package pkgA; 2. public class Abc { 3. int a = 5; 4. protected int b = 6; 5. public int c = 7; 6. } 3. package pkgB; 4. import pkgA.*; 5. public class Def { 6. public static void main(String[] args) { 7. Abc f = new Abc(); 8. System.out.print(" " + f.a); 9. System.out.print(" " + f.b); 10. System.out.print(" " + f.c); 11. } 12. } What is the result when the second program is run? (Choose all that apply) Compilation fails with an error on line 9 5 followed by an exception Compilation fails with an error on line 7 Compilation fails with an error on line 8

Submit

81. Given: public void testIfA() { if (testIfB("True")) { System.out.println("True"); } else { System.out.println("Not true"); } } public Boolean testIfB(String str) { return Boolean.valueOf(str); } What is the result when method testIfA is invoked? true Not true An exception is thrown at runtime. none

Submit

82. Given the following program,which statements are true? (Choose TWO) Public class Exception { public static void main(String[] args) { try { if(args.length == 0) return; System.out.println(args[0]); }finally { System.out.println("The end"); }}} If run with no arguments,th e program will produce no output If run with no arguments,th e program will produce "The end" If run with one arguments,th e program will print the given argument followed by "The end" If run with one arguments,th e program will simply print the given argument

Submit

83. What will the output of following code? 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"); finished Exception compilation fails ArithmeticExc eption

Submit

84. Choose TWO correct options: OutputStrea m is the abstract superclass of all classes that represent an outputstream of bytes. Subclasses of the class Reader are used to read character streams. To write characters to an outputstream, you have to make use of the class CharacterOut putStream. To write an object to a file, you use the class ObjectFileWri ter

Submit

85. Given: import java.util.*; public class Explorer3 { public static void main(String[] args) { TreeSet<Integer> s = new TreeSet<Integer>(); TreeSet<Integer> subs = new TreeSet<Integer>(); for(int i = 606; i < 613; i++) if(i%2 == 0) s.add(i); subs = (TreeSet)s.subSet(608, true, 611, true); subs.add(629); System.out.println(s + " " + subs); } } What is the result? Compilation fails. [608, 610, 612, 629] [608, 610] An exception is thrown at runtime. [608, 610, 612, 629] [608, 610, 629]

Submit

86. Which two can be used to create a new Thread? Implement java.lang.Run nable and implement the run() method. Extend java.lang.Thr ead and override the run() method. Implement java.lang.Thr ead and implement the start() method. Extend java.lang.Run nable and override the start() method.

Submit

87. Which of the following statements regarding static methods are correct? (2 answers) static methods are difficult to maintain, because you can not change their implementati on. static methods can be called using an object reference to an object of the class in which this method is defined. static methods are always public, because they are defined at class-level. static methods do not have direct access to non-static methods which are defined inside the same class.

Submit

88. Public class MyProgram { public static void throwit() { throw new RuntimeException(); } public static void main(String args[]) { try { System.out.println("Hello world "); throwit(); System.out.println("Done with try block "); } finally { System.out.println("Finally executing "); } } } which answer most closely indicates the behavior of the program? The program will not compile. The program will print Hello world, then will print that a RuntimeExce ption has occurred, then will print Done with try block, and then will print Finally executing. The program will print Hello world, then will print that a RuntimeExce ption has occurred, and then will print Finally executing. The program will print Hello world, then will print Finally executing, then will print that a RuntimeExce ption has occurred.

Submit

89. Which can appropriately be thrown by a programmer using Java SE technology to create a desktop application? ClassCastEx ception NullPointerEx ception NoClassDefF oundError NumberForm atException

Submit

90. Which statements are true about maps? (Choose TWO) The return type of the values() method is set Changes made in the Set view returned by keySet() will be reflected in the original map The Map interface extends the Collection interface All keys in a map are unique

Submit

91. Choose the correct option: A try statement must have at least one correspondin g catch block Multiple catch statements can catch the same class of exception more than once. An Error that might be thrown in a method must be declared as thrown by that method, or be handled within that method. Except in case of VM shutdown, if a try block starts to execute, a correspondin g finally block will always start to execute.

Submit

92. Class Test{ public static void main(String[] args){ try{ Integer.parseInt("1.0"); } catch(Exception e){ System.out.println("Exception occurred"); } catch(RuntimeException ex){ System.out.println("RuntimeException"); } } } consider the code above & select the proper output from the options. Exception occurred RuntimeExce ption Exception occurred Runtime Exception does not compile

Submit

93. Consider the following code and choose the correct option: int array[] = new int[10]; array[-1] = 0; compiles successfully does not compile runtime error none of the listed options

Submit

94. Given: public class TestSeven extends Thread { private static int x; public synchronized void doThings() { int current = x; current++; x = current; } public void run() { doThings(); } } Which statement is true? Compilation fails. Synchronizin g the run() method would make the class thread-safe. Declaring the doThings() method as static would make the class threadsafe. An exception is thrown at runtime.

Submit

95. Consider the following code: System.out.print("Start "); try { System.out.print("Hello world"); throw new FileNotFoundException(); } System.out.print(" Catch Here "); /* Line 7 */ catch(EOFException e) { System.out.print("End of file exception"); } catch(FileNotFoundException e) { System.out.print("File not found"); } given that EOFException and FileNotFoundException are both subclasses of IOException. If this block of code is pasted in a method, choose the best option. The code will not compile. Code output: Start Hello world File Not Found Code output: Start Hello world End of file exception . Code output: Start Hello world Catch Here File not found.

Submit

96. Which are true with respect to finally block? (Choose THREE) Used to release the resources which are obtained in try block. Writing finally block is optional. When an exception occurs then a part of try block will execute one appropriate catch block and finally block will be executed. When no exception occurs then complete try block and finally block will execute but no catch block will execute.

Submit

97. Which of the following statements are true? (Choose TWO) Both wait() and notify() must be called from a synchronized context. The wait() method is overloaded to accept a duration A thread will resume execution as soon as its sleep duration expires. The notify() method is overloaded to accept a duration

Submit

98. Class Animal { public String noise() { return "peep"; } } class Dog extends Animal { public String noise() { return "bark"; } } class Cat extends Animal { public String noise() { return "meow"; } } class try1{ public static void main(String[] args){ Animal animal = new Dog(); Cat cat = (Cat)animal; System.out.println(cat.noise()); }}consider the code above & select the proper output from the options. bark meow Compilation fails An exception is thrown at runtime.

Submit

99. Given: class X { public void foo() { System.out.print("X "); } } public class SubB extends X { public void foo() throws RuntimeException { super.foo(); if (true) throw new RuntimeException(); System.out.print("B "); } public static void main(String[] args) { new SubB().foo(); } } What is the result? X, followed by an Exception. No output, and an Exception is thrown. X, followed by an Exception, followed by B. none

Submit

100. Consider the following code and choose the correct option: class Test{ static void display(){ throw new RuntimeException(); } public static void main(String args[]){ try{display(); }catch(Exception e){ } catch(RuntimeException re){} finally{System.out.println("exit");}}} exit Compiles and no output Compilation fails Compiles but exception at runtime

Submit

101. Consider the following code and choose the correct option: class Test{ static void display(){ throw new RuntimeException(); } public static void main(String args[]){ try{display(); }catch(Exception e){ throw new NullPointerException();} finally{try{ display(); }catch(NullPointerException e){ System.out.println("caught");} finally{ System.out.println("exit");}}}} caught exit exit exit RuntimeExce ption thrown at run time Compilation fails

Submit

102. Consider the code & choose the correct output: class Threads2 implements Runnable { public void run() { System.out.println("run."); throw new RuntimeException("Problem"); } public static void main(String[] args) { Thread t = new Thread(new Threads2()); t.start(); System.out.println("End of method."); } } java.lang.Run timeExceptio n: Problem run java.lang.Run timeExceptio n: Problem End of method. java.lang.Run timeExceptio n: Problem End of method. run. java.lang.Run timeExceptio n: Problem

Submit

103. Given: static void test() { try { String x = null; System.out.print(x.toString() + " "); } finally { System.out.print("finally "); } } public static void main(String[] args) { try { test(); } catch (Exception ex) { System.out.print("exception "); } } What is the result? null Compilation fails. finally exception finally

Submit

104. Which statements describe guaranteed behaviour of the garbage collection and finalization mechanisms? (Choose TWO) An object is deleted as soon as there are no more references that denote the object The finilize() method will eventually be called on every object The finalize() method will never be called more than once on an object An object will not be garbage collected as long as it possible for a live thread to access it through a reference.

Submit

105. Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ Long L = null; long l = L; System.out.println(L); System.out.println(l); }} null 0 Compilation error Compiles but error at run time 0 null

Submit

106. In the given code snippet try { int a = Integer.parseInt("one"); } what is used to create an appropriate catch block? (Choose all that apply.) A. ClassCastException B. IllegalStateException C. NumberFormatException D. IllegalArgumentException ClassCastEx ception NumberForm atException IllegalStateEx ception IllegalArgume nt Exception

Submit

107. Consider the following code and choose the correct option: class Test{ public static void parse(String str) { try { int num = Integer.parseInt(str); } catch (NumberFormatException nfe) { num = 0; } finally { System.out.println(num); } } public static void main(String[] args) { parse("one"); } 0 NumberForm atException thrown at runtime Compilation fails ParseExcepti on thrown at runtime

Submit

108. Choose TWO correct options: If an exception is not caught in a method,the method will terminate and normal execution will resume An overriding method must declare that it throws the same exception classes as the method it overrides The main() method of a program can declare that it throws checked exception A method declaring that it throws a certain exception class may throw instances of any subclass of that exception class

Submit

109. Consider the code below & select the correct ouput from the options: public class Test{ Integer i; int x; Test(int y){ x=i+y; System.out.println(x); } public static void main(String[] args) { new Test(new Integer(5)); }} 5 Compilation error Compiles but error at run time

Submit

110. Consider the following code and choose the correct option: class Test{ static void display(){ throw new RuntimeException(); } public static void main(String args[]){ try{ display(); }catch(Exception e){ throw new NullPointerException();} finally{try{ display(); }catch(NullPointerException e){ System.out.println("caught");} System.out.println("exit");}}} caught exit exit Compilation fails Compiles but exception at runtime

Submit
×
Saved
Thank you for your feedback!
View My Results
Cancel
  • All
    All (110)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Given: ...
Consider the following code and choose the ...
Given: ...
Consider the following code and choose the ...
What is the output : ...
Which of the following loop bodies DOES ...
Given: ...
Switch(x) ...
What will be the output of the program? ...
Consider the following code and choose the ...
Examine the following code: ...
Given: ...
Given: ...
Which of the following statements about ...
Import java.util.SortedSet; ...
11. double input = 314159.26; ...
Consider the following code and choose the ...
What does the following code fragment write ...
Class AutoBox { ...
What is the output : ...
Which one do you like?Which collection implementation is suitable for ...
Consider the following code and choose the ...
Public class SwitchTest ...
Class s implements Runnable ...
What will be the output of following code? ...
What are the thing to be placed to complete ...
What will be the result of attempting to compile ...
What is the output of the following code : ...
Consider the following code and choose the ...
Given: ...
Consider the following code and choose the ...
Class Trial{ ...
Given: ...
Which four can be thrown using the throw ...
Given: ...
What will be the output of the program? ...
What is the output : ...
Which of the following statements is TRUE ...
Given: ...
Given: ...
Public void foo( boolean a, boolean b) ...
Public class While ...
Consider the following code and choose the ...
What is the value of 'n' after executing the ...
Which digit,and in what order,will be printed ...
Consider the following code and choose the ...
Which three of the following are methods of ...
Which of the following is a checked ...
Given: ...
What is wrong with the following code? ...
What will be the output of following code? ...
What will be the output of the program? ...
Consider the following code and choose the ...
Class X implements Runnable ...
Which of the following statements is true? ...
Given: ...
If a method is capable of causing an ...
Which statement is true? ...
Which of the following allows a programmer to ...
Which of the following methods are static? ...
Which of the following statements are true ...
Which of these statements are true? ...
Consider the following code and choose the ...
What will happen when you attempt to ...
Class Trial{ ...
Consider the following code and choose the ...
Consider the following code and choose the ...
Public class Test { ...
Which statement is true? ...
Int I = 0; ...
Class PropagateException{ ...
A) Checked Exception must be explicity ...
Public class RTExcept ...
Class Trial{ ...
Which statement is true? ...
What is the keyword to use when the access ...
Public static void parse(String str) { ...
The exceptions for which the compiler doesn't ...
Given: ...
Given two programs: ...
Given: ...
Given the following program,which statements ...
What will the output of following code? ...
Choose TWO correct options: ...
Given: ...
Which two can be used to create a new ...
Which of the following statements regarding ...
Public class MyProgram ...
Which can appropriately be thrown by a ...
Which statements are true about maps? ...
Choose the correct option: ...
Class Test{ ...
Consider the following code and choose the ...
Given: ...
Consider the following code: ...
Which are true with respect to finally block? ...
Which of the following statements are true? ...
Class Animal { public String noise() { return ...
Given: ...
Consider the following code and choose the ...
Consider the following code and choose the ...
Consider the code & choose the correct ...
Given: ...
Which statements describe guaranteed ...
Consider the following code and choose the ...
In the given code snippet ...
Consider the following code and choose the ...
Choose TWO correct options: ...
Consider the code below & select the correct ...
Consider the following code and choose the ...
play-Mute sad happy unanswered_answer up-hover down-hover success oval cancel Check box square blue
Alert!