1 / 19

MCQ Questions on Java Online Test

Here to get 50 Java MCQs for your upskill program. you can easily download & solve it. Synergisticit best developers Prepares new technology based mcqs for you !<br>

28352
Download Presentation

MCQ Questions on Java Online Test

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MCQ Questions on Java Online Test 1. The hasMoreElements() method of Enumeration in Iterator has been changed to: a) hasNextElement() b) hasNext() c) isNext() d) name remains the same 2. What does TreeSet use internally to store elements? a) HashMap b) LinkedHashMap c) TreeMap d) HashSet 3. Select the lines that will compile without warning or error. *

  2. a) float f=1.3 b) char c=2.58 c) byte b=257 d) boolean b=null e) int i=10 4. Which of these is not an interface in the Collections Framework? a. Collection b. Group c. Set d. List 5. Which of these collection classes can grow dynamically? a. Array b. Arrays c. ArrayList d. None of these 6. Which of the interface restricts duplicate elements? a. Set b. List c. Map d. All of these 7. A HashMap allows the existence of: a. null values b. one null key c. None of these d. All of these

  3. 8. How can you guarantee the accuracy and efficiency of a HashMap? a. override equals method b. override hashCode method c. None of these d. All of these 9. The Comparable interface contains which method? a. toCompare b. compare c. compareTo d. compareWith 10. What implementation of Iterator will traverse a collection in both directions? a. Iterator b. ListIterator c. SetIterator d. MapIterator 11. Name the Iterator that can throw a ConcurrentModificationException? a. Fail-fast Iterators b. Fail-safe Iterators c. All of these d. None of these 12. Which of these uses less memory and is faster? a. ListEnumeration b. Iterator c. Enumeration

  4. d. ListIterator 13. Which is the ideal option for a multi-threaded environment? a. WeakHashMap b. Hashtable c. HashMap d. ConcurrentHashMap 14. How many are the default number of segments / Partitions in Concurrent Hash Map? a.12 b.32 c.4 d.16 15. What is the default capacity of a Vector? a.10 b.12 c.8 d.16 16. Which of these provides optimal performance for the removal and insertion from the middle of the list? a. Vector b. ArrayList c. LinkedList d. All of these 17. ________ does NOT implement the Collection interface? a. List

  5. b. Map c. Set d. None of these 18. Which is the default capacity of an ArrayList? a.12 b.16 c.1 d.10 19. previousIndex()and nextIndex()are methods of which interface? a. IndexIterator b. Iterator c. ListIterator d. NextPreviousIterator 20. ArrayList implements: a. List b. RandomAccess c. Cloneable d. All of these 21. Which of the following allows the storage of many null values? a. Set b. List c. None of these d. All of these 22. Which of the following allows the removal of elements from a collection?

  6. a. Enumeration b. Iterator c. Both d. None 23. LinkedList implements: a. Deque b. List c. None d. All 24. Vector extends to what? a. ArrayList b. LinkedList c. AbstractList d. None 25. Enumeration returned by Vector is called? a. fail-fast b. fail-safe c. none 26. Which does not allow to store a null value? a. TreeSet b. LinkedHashSet c. HashSet d. None

  7. 27. From Java 5 onwards, which of the following is recommended to replace Hashtable? a. ConcurrentHashMap b. HashMap c. ConcurrentHashtable d. None 28. Iterator returned by Vector is known as? a.fail-fast b.fail-safe c.none 29. What labels how well an algorithm is performing in best, average, or worse case scenarios? a. Big-B b. Big-O c. Big-Data d. Big-N 30. An ordered array has a search time complexity of? a. O(n) b. O(1) c. O(log n) d. O(n-1) 31. Which Map class is preferred in a multi-threading environment for maintaining the natural order of keys? a. ConcurrentHashMap b. ConcurrentSkipListMap c. ConcurrentMap

  8. d. all 32. TreeMap implements: a. Dictionary b. HashMap c. AbstractMap d. NavigableMap 33. Which list class should be favored considering performance constraints in a multi-threading environment? a. Vector b. CopyOnWriteArrayList c. ArrayList d. ConcurrentArrayList 34. Which Set class should be preferred considering performance constraints in a multi-threading environment? a. HashSet b. ConcurrentSkipListSet c. LinkedHashSet d. CopyOnWriteArraySet 35. Which Map class should you prefer considering performance constraints in a multi-threading environment? a. Hashtable b. CopyOnWriteMap c. ConcurrentHashMap d. ConcurrentMap 36. Which of the these does NOT have an index-based structure?

  9. a. List b. Set c. Map d. None 37. Methods such as shuffle, reverse, and sort are available in: a. Object b. Collection c. Collections d. Apache Commons Collections 38. java.util.Collections is a: a. class b. interface c. object d. none 39. Which allows the storage of null key and several null values? a. Hashtable b. HashMap c. Both d. None 40. Which of the following allows duplicate elements? a. Set b. List c. All d. None

  10. 41. What will happen when you attempt to compile and run the given code? public class MyClass { public static void main(String arguments[]){ amethod(arguments); } public void amethod(String[] arguments) { System.out.println(arguments); System.out.println(arguments[1]); } } a. error can’t make a static reference to void amethod. b. error method main not right c. error array must include parameter d. amethod must be declared with String 42. What will print if you try to compile and run the given code? int i=9; switch (i) { default: System.out.println("default"); case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); } a. default b. default, zero c. error default clause not defined d. no output displayed 43. What will happen if you try to compile and run the given code? public class Tux extends Thread{ static String sName = "vandeleur"; public static void main(String argv[]){ Tux t = new Tux(); t.piggy(sName); System.out.println(sName); } public void piggy(String sName){ sName = sName + " wiggy"; start(); } public void run(){ for(int i=0;i < 4; i++){ sName = sName + " " + i; } } } a. Compile-time error b. Compilation and output of "vandeleur wiggy" c. Compilation and output of "vandeleur wiggy 0 1 2 3" d. Compilation and output of either "vandeleur", "vandeleur 0", "vandeleur 0 1" "vandaleur 0 1 2" or "vandaleur 0 1 2 3"

  11. 44. What will be displayed when you attempt to compile and run the following code? //Code start import java.awt.*; public class Butt extends Frame{ public static void main(String argv[]){ Butt MyBut=new Butt(); } Butt(){ Button HelloBut=new Button("Hello"); Button ByeBut=new Button("Bye"); add(HelloBut); add(ByeBut); setSize(300,300); setVisible(true); } } //Code end a. Two buttons side by side occupying entire frame, Bye on the right and Hello on the left b. One button occupying all of the frame saying Hello c. One button occupying all of the frame saying Bye d. Two buttons at the frame top, one saying Bye and the other saying Hello 45. Which statement is true of the following code? public class Agg{ public static void main(String argv[]){ Agg a = new Agg();

  12. a.go(); } public void go(){ DSRoss ds1 = new DSRoss("one"); ds1.start(); } } class DSRoss extends Thread{ private String sTname=""; DSRoss(String s){ sTname = s; } public void run(){ notwait(); System.out.println("finished"); } public void notwait(){ while(true){ try{ System.out.println("waiting"); wait(); }catch(InterruptedException ie){} System.out.println(sTname); notifyAll(); } } } a. Cause a compile-time error

  13. b. Compilation and output of “waiting.” c. Compilation and output of “waiting” succeeded by “finished.” d. Runtime error; an exception will be thrown 46. What gets printed out if you run the code below? String s=new String("Bicycle"); int iBegin=1; char iEnd=3; System.out.println(s.substring(iBegin,iEnd)); a. Bic b. ic c. icy d. error: no method matching substring(int,char) 47. What modifiers would be legal at XX in the code? public class MyClass1 { public static void main(String argv[]){ } /*Modifier at XX */ class MyInner {} } a. public b. private c. static d. All of the above 48.What will happen if you try to compile and run the following code? class Background implements Runnable{ int i=0; public int run(){

  14. while(true){ i++; System.out.println("i="+i); } //End while return 1; }//End run }//End class a. It will compile, and the increasing value of i will be printed out by the run method. b. It will compile, and the increasing value of i will be printed out by calling start. c. The code will create an error at compile time. d. Compilation will cause an error as while cannot take a parameter of true. 49. What test will you need to put in place of the comment line in the following code? //place test here to result in an output of the string Equal public class EqTest{ public static void main(String argv[]){ EqTest e=new EqTest(); } EqTest(){ String s="Java"; String s2="java";

  15. //place test here { System.out.println("Equal"); }else { System.out.println("Not equal"); } } } a. if(s==s2) b. if(s.equals(s2) c. if(s.equalsIgnoreCase(s2)) d. if(s.noCaseMatch(s2)) 50.If you make a TextField with a constructor for setting it to occupy 5 columns, what difference will it create if you use it with a fixed-pitch typewriter-style font such as Courier or a proportional font such as Times Roman? a. With a fixed font, you will see 5 characters, while with a proportional font, it will depend on the characters’ width b. With a fixed font, you will see 5 characters, while with a proportional font, it will make the field expand to fit the text c. The columns setting does not affect the displayed number of characters d. In both options, it will show precisely 5 characters 51.Which code placed after the comment //For loop would lead to the population of every array ia[] element with a value from variable i.? public class Lin{ public static void main(String argv[]){ Lin l = new Lin(); l.amethod(); }

  16. public void amethod(){ int ia[] = new int[4]; //Start For loop { ia[i]=i; System.out.println(ia[i]); } } } a. for(int i=0; i < ia.length() -1; i++) b. for (int i=0; i< ia.length(); i++) c. for(int i=1; i < 4; i++) d. for(int i=0; i< ia.length;i++) 52. What will happen if you attempt compiling and running this code? public class Ref{ public static void main(String argv[]){ Ref r = new Ref(); r.amethod(r); } public void amethod(Ref r){ int i=99; multi(r); System.out.println(i); } public void multi(Ref r){ r.i = r.i*2; } }

  17. a. Error at compile time b. An output of 99 c. An output of 198 d. An error at runtime 53. Given the following code,what code would be most likely for the body of the ioCall method? import java.io.*; public class Th{ public static void main(String argv[]){ Th t = new Th(); t.amethod(); } public void amethod(){ try{ ioCall(); }catch(IOException ioe){} } } a. public void ioCall ()throws IOException{ DataInputStream din = new DataInputStream(System.in); din.readChar(); } b. public void ioCall ()throw IOException{ DataInputStream din = new DataInputStream(System.in); din.readChar(); } c. public void ioCall (){ DataInputStream din = new DataInputStream(System.in);

  18. din.readChar(); } d. public void ioCall throws IOException(){ DataInputStream din = new DataInputStream(System.in); din.readChar(); } 54.Which statement is true about the following code? public class Rpcraven{ public static void main(String argv[]){ Pmcraven pm1 = new Pmcraven("One"); pm1.run(); Pmcraven pm2 = new Pmcraven("Two"); pm2.run(); } } class Pmcraven extends Thread{ private String sTname=""; Pmcraven(String s){ sTname = s; } public void run(){ for(int i =0; i < 2 ; i++){ try{ sleep(1000); }catch(InterruptedException e){} yield(); System.out.println(sTname); } } } a. Output of One One Two Two

  19. b. Compile time error, class Rpcraven doesn’t import java.lang.Thread c. Output of One Two One Two d. Compilation but no output at runtime 55. Which of the following most closely defines a bitset collection? a. A class which contains groups of unique sequences of bits b. A method for flipping individual bits in an instance of a primitive type c. An array of boolean primitives that indicate ones or zeros d. A collection for storing bits as an on-off information, like a vector of bits Next : Online Practice MCQs on Java Programming

More Related