Java MCQ – Home
Java Basic MCQ
➤ Java Hello World MCQ
➤ Find Java Keywords
➤ Java Identifier Quiz
➤ Java Data Types Quiz
➤ If-Else MCQ in Java-1
➤ If-Else MCQ in Java-2
Object class MCQ
➤ Object Class Quiz
➤ equals() Method Quiz
➤ Hashcode Value Quiz
➤ toString() Method Quiz
➤ Clone() Method Quiz
Multithreading MCQ
➤ Define a Thread-1
➤ Define a Thread-2
➤ Get/set ThreadName
➤ Thread State MCQ
➤ Thread Priority MCQ
➤ Yield(), join() & sleep()
➤ Synchronization MCQ
➤ Interthread Comms
➤ Deadlock, Daemon
Exception Handling
➤ Exception Handling-1
➤ Exception Handling-2
➤ Exception Handling-3
➤ Java try-catch MCQ-1
➤ Java try-catch MCQ-2
➤ Java try-catch MCQ-3
➤ Nested try-catch MCQ
➤ throw Keyword MCQ
➤ finally Block MCQ-1
➤ finally Block MCQ-2
➤ throws Keyword MCQ
Generics MCQ
➤ Java Generics Quiz-1
➤ Java Generics Quiz-2
➤ Java Generics Quiz-3
Collection Framework
➤ Collections Quiz-1
➤ Collections Quiz-2
➤ ArrayList MCQ-1
➤ ArrayList MCQ-2
➤ LinkedList MCQ
➤ Vector Stack MCQ
➤ Java Cursors MCQ
➤ Java TreeSet MCQ
➤ TreeSet & Comparator
Java Collections Quiz-2 | In Java, collection framework classes are used to store elements in value or key-value format without size limitation. We have listed some basic and fundamental Java Collections Quiz, answer them. Previously we have seen:- Java Collections Quiz-1
Also see- Java Collection Framework Overview, Java Collection Interface, List Interface in Java
Q1) Which of the following classes are direct/indirect implementation classes of the List interface?
a) ArrayList, LinkedList, Vector, and Stack
b) ArrayList and LinkedList
c) ArrayList, LinkedList, and Vector
d) None of these
View Answer
Answer:- a) ArrayList, LinkedList, Vector, and StackQ2) Vector and Stack classes were introduced in?
a) 1.0 Version
b) 1.2 Version
c) 1.5 Version
d) 1.8 Version
View Answer
Answer:- a) 1.0 VersionThe Vector and Stack classes were introduced in Java 1.0 Version therefore they are also called legacy classes.
Q3) Which of the following options are true about the List interface and its implementation classes?
a) Duplicates are allowed.
b) Insertion order will be preserved.
c) Null insertion is allowed.
d) All of these.
View Answer
Answer:- d) All of these.In List and its implementation classes, duplicates are allowed & insertion orders must be preserved. They can store null values.
Q4) Vector and Stack classes are?
a) Thread-safe classes
b) Non-Thread-safe classes
c) Both
d) None of these
View Answer
Answer:- a) Thread-safe classesThe Vector and Stack classes were introduced in the 1.0 version and they are introduced as Thread-safe classes. It means all the methods of these classes are declared as synchronized. Therefore, for every method call on these class objects, JVM locks and unlocks the object.
Q5) ArrayList and LinkedList classes are?
a) Thread-safe classes
b) Non-Thread-safe classes
c) Both
d) None of these
View Answer
Answer:- b) Non-Thread-safe classesArrayList and LinkedList classes are non-thread-safe classes, it means all the methods of these classes are non-synchronized methods.
Q6) Which of the following classes are implementation classes/interfaces of the Set interface?
a) HashSet, and LinkedHashSet
b) NavigableSet, and TreeSet
c) HashSet, LinkedHashSet, NavigableSet, and TreeSet
d) HashSet, LinkedHashSet, SortedSet, NavigableSet, and TreeSet
View Answer
Answer:- d) HashSet, LinkedHashSet, SortedSet, NavigableSet, and TreeSetQ7) SortedSet and NavigableSet are an interface or class?
a) interface
b) class
c) abstract class
d) Enum
View Answer
Answer:- a) interfaceQ8) Which of the following statements are valid about the Set interface and its implementation classes?
- Duplicates are allowed.
- Duplicates are not allowed.
- Insertion order preserved.
- Insertion order not preserved.
a) 1 & 3
b) 1 & 4
c) 2 & 3
d) 2 & 4
View Answer
Answer:- d) 2 & 4In the Set interface and its implementation classes, duplicates are not allowed & insertion order is not preserved.
Q9) Which of the following statements are true about SortedSet(I)?
a) Duplicates are not allowed.
b) Insertion order is not preserved.
c) Elements are inserted according to some sorting order.
d) All of these
View Answer
Answer:- d) All of theseThe SortedSet(I) implements Set(I). The Set(I) doesn’t allow duplicate values, and the insertion order is not preserved. If we want to insert elements according to some sorting order then SortedSet(I) can be used.
Q10) By default Queue(I) follows?
a) FIFO (First in First out)
b) LIFO (Last in First out)
c) Both
d) None of these
View Answer
Answer:- a) FIFO (First in First out)Usually, the queue follows FIFO (first in first out) order but based on our requirement we can implement our own priority order also.
Q11) Map(I) implements Collection(I)?
a) True
b) False
c) None of these
View Answer
Answer:- b) FalseMap(I) doesn’t implements Collection(I).
Q12) Which of the following statements are true about Map(I) and its subclasses?
a) Both key and value must be numbers.
b) Key should be number, and Value must be String.
c) Both key and value must be String.
d) Both key and value should be Objects.
View Answer
Answer:- d) Both key and value should be Object.Both key & values are objects. Hence key can be number, String, and e.t.c. Similarly, the value also can be number, string, and e.t.c.
Q13) Which of the following statements are true about Map(I) and its subclasses?
a) Key can’t be duplicated.
b) Value can’t be duplicated.
c) Both keys & values can’t be duplicated.
d) Duplicate is allowed for both key & value.
View Answer
Answer:- a) Key can’t be duplicated.In Map, Duplicate keys are not allowed but values can be duplicated.
Q14) If we want to represent a group of key-value pairs according to some sorting order of keys then we should go for?
a) Hashtable
b) SortedMap
c) HashMap
d) None of these
View Answer
Answer:- b) SortedMapIf we want to represent a group of key-value pairs according to some sorting order of keys then we should go for SortedMap.
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!