MCQOPTIONS
Saved Bookmarks
This section includes 1671 Mcqs, each offering curated multiple-choice questions to sharpen your Technical Programming knowledge and support exam preparation. Choose a topic below to get started.
| 951. |
What is the output of this program? import java.util.*; class Linkedlist { public static void main(String args[]) { LinkedList obj = new LinkedList(); obj.add("A"); obj.add("B"); obj.add("C"); obj.addFirst("D"); System.out.println(obj); } } |
| A. | [A, B, C]. |
| B. | [D, B, C]. |
| C. | [A, B, C, D]. |
| D. | [D, A, B, C]. |
| Answer» E. | |
| 952. |
Which of these method is used to change an element in a LinkedList Object? |
| A. | change() |
| B. | set() |
| C. | redo() |
| D. | add() |
| Answer» C. redo() | |
| 953. |
Which of these methods can be used to delete the last element in a LinkedList object? |
| A. | remove() |
| B. | delete() |
| C. | removeLast() |
| D. | deleteLast() |
| Answer» D. deleteLast() | |
| 954. |
Which of these method of HashSet class is used to add elements to its object? |
| A. | add() |
| B. | Add() |
| C. | addFirst() |
| D. | insert() |
| Answer» B. Add() | |
| 955. |
Which of these method is used to add an element to the start of a LinkedList object? |
| A. | add() |
| B. | first() |
| C. | AddFirst() |
| D. | addFirst() |
| Answer» E. | |
| 956. |
Which of these classes implements Set interface? |
| A. | ArrayList |
| B. | HashSet |
| C. | HashSet |
| D. | DynamicList |
| Answer» C. HashSet | |
| 957. |
Which of these standard collection classes implements a linked list data structure? |
| A. | AbstractList |
| B. | LinkedList |
| C. | HashSet |
| D. | AbstractSet |
| Answer» C. HashSet | |
| 958. |
What is the unique feature of LinkedHashSet? |
| A. | It is not a valid class |
| B. | It maintains the insertion order and guarantees uniqueness |
| C. | It provides a way to store key values with uniqueness |
| D. | The elements in the collection are linked to each other |
| Answer» C. It provides a way to store key values with uniqueness | |
| 959. |
What happens if two threads simultaneously modify TreeSet? |
| A. | ConcurrentModificationException is thrown |
| B. | Both threads can perform action successfully |
| C. | FailFastException is thrown |
| D. | IteratorModificationException is thrown |
| Answer» B. Both threads can perform action successfully | |
| 960. |
What is the difference between TreeSet and SortedSet? |
| A. | TreeSet is more efficient than SortedSet |
| B. | SortedSet is more efficient than TreeSet |
| C. | TreeSet is an interface; SortedSet is a concrete class |
| D. | SortedSet is an interface; TreeSet is a concrete class |
| Answer» E. | |
| 961. |
Set has contains(Object o) method? |
| A. | True |
| B. | False |
| Answer» B. False | |
| 962. |
What is the output of below code snippet? public class Test { public static void main(String[] args) { Set s = new HashSet(); s.add(new Long(10)); s.add(new Integer(10)); for(Object object : s) { System.out.println("test - "+object); } } } |
| A. | Test – 10 Test – 10 |
| B. | Test – 10 |
| C. | Runtime Exception |
| D. | Compilation Failure |
| Answer» B. Test – 10 | |
| 963. |
What is the relation between hashset and hashmap? |
| A. | HashSet internally implements HashMap |
| B. | HashMap internally implements HashSet |
| C. | HashMap is the interface; HashSet is the concrete class |
| D. | HashSet is the interface; HashMap is the concrete class |
| Answer» B. HashMap internally implements HashSet | |
| 964. |
What is the initial capacity and load factor of HashSet? |
| A. | 10, 1.0 |
| B. | 32, 0.75 |
| C. | 16, 0.75 |
| D. | 32, 1.0 |
| Answer» D. 32, 1.0 | |
| 965. |
What does Collections.emptySet() return? |
| A. | Immutable Set |
| B. | Mutable Set |
| C. | The type of Set depends on the parameter passed to the emptySet() method |
| D. | Null object |
| Answer» B. Mutable Set | |
| 966. |
Do we have get(Object o) method in HashSet? |
| A. | True |
| B. | false |
| Answer» C. | |
| 967. |
What is the default clone of HashSet? |
| A. | Deep clone |
| B. | Deep clone |
| C. | Plain clone |
| D. | Hollow clone |
| Answer» C. Plain clone | |
| 968. |
When an array is passed to a method, will the content of the array undergo changes with the actions carried within the function? |
| A. | True |
| B. | False |
| Answer» B. False | |
| 969. |
What is the worst case complexity of accessing an element in ArrayList? |
| A. | O(n) |
| B. | O(1) |
| C. | O(nlogn) |
| D. | O(2) |
| Answer» C. O(nlogn) | |
| 970. |
Which of the below is not an implementation of List interface? |
| A. | RoleUnresolvedList |
| B. | Stack |
| C. | AttibuteList |
| D. | SessionList |
| Answer» E. | |
| 971. |
Which class provides thread safe implementation of List? |
| A. | ArrayList |
| B. | CopyOnWriteArrayList |
| C. | HashList |
| D. | List |
| Answer» C. HashList | |
| 972. |
What is the difference between length() and size() of ArrayList? |
| A. | length() and size() return the same value |
| B. | length() is not defined in ArrayList |
| C. | size() is not defined in ArrayList |
| D. | length() returns the capacity of ArrayList and size() returns the actual number of elements stored in the list |
| Answer» E. | |
| 973. |
How is Arrays.asList() different than the standard way of initialising List? |
| A. | Both are same |
| B. | Arrays.asList() throws compilation error |
| C. | Arrays.asList() returns a fixed length list and doesn’t allow to add or remove elements |
| D. | We cannot access the list returned using Arrays.asList() |
| Answer» D. We cannot access the list returned using Arrays.asList() | |
| 974. |
When two threads access the same ArrayList object what is the outcome of program? |
| A. | Both are able to access the object |
| B. | ConcurrentModificationException is thrown |
| C. | One thread is able to access the object and second thread gets Null Pointer exception |
| D. | One thread is able to access the object and second thread will wait till control is passed to second one |
| Answer» C. One thread is able to access the object and second thread gets Null Pointer exception | |
| 975. |
How to sort elements of ArrayList? |
| A. | Collection.sort(listObj); |
| B. | Collections.sort(listObj); |
| C. | listObj.sort(); |
| D. | Sorter.sortAsc(listObj); |
| Answer» C. listObj.sort(); | |
| 976. |
How to remove duplicates from List? |
| A. | HashSet<String> listToSet = new HashSet<String>(duplicateList); |
| B. | HashSet<String> listToSet = duplicateList.toSet(); |
| C. | HashSet<String> listToSet = Collections.convertToSet(duplicateList); |
| D. | HashSet<String> listToSet = duplicateList.getSet(); |
| Answer» B. HashSet<String> listToSet = duplicateList.toSet(); | |
| 977. |
How can we remove an object from ArrayList? |
| A. | remove() method |
| B. | using Iterator |
| C. | remove() method and using Iterator |
| D. | delete() method |
| Answer» D. delete() method | |
| 978. |
If large number of items are stored in hash bucket, what happens to the internal structure? |
| A. | The bucket will switch from LinkedList to BalancedTree |
| B. | The bucket will increase its size by a factor of load size defined |
| C. | The LinkedList will be replaced by another hashmap |
| D. | Any further addition throws Overflow exception |
| Answer» B. The bucket will increase its size by a factor of load size defined | |
| 979. |
What is the output of below snippet? public class Demo { public static void main(String[] args) { Map sampleMap = new TreeMap(); sampleMap.put(1, null); sampleMap.put(5, null); sampleMap.put(3, null); sampleMap.put(2, null); sampleMap.put(4, null); System.out.println(sampleMap); } } |
| A. | {1=null, 2=null, 3=null, 4=null, 5=null} |
| B. | {5=null} |
| C. | Exception is thrown |
| D. | {1=null, 5=null, 3=null, 2=null, 4=null} |
| Answer» B. {5=null} | |
| 980. |
How to externally synchronize hashmap? |
| A. | HashMap.synchronize(HashMap a); |
| B. | HashMap a = new HashMap(); a.synchronize(); |
| C. | Collections.synchronizedMap(new HashMap<String, String>()); |
| D. | Collections.synchronize(new HashMap<String, String>()); |
| Answer» D. Collections.synchronize(new HashMap<String, String>()); | |
| 981. |
If two threads access the same hashmap at the same time, what would happen? |
| A. | ConcurrentModificationException |
| B. | NullPointerException |
| C. | ClassNotFoundException |
| D. | RuntimeException |
| Answer» B. NullPointerException | |
| 982. |
Is hashmap an ordered collection? |
| A. | True |
| B. | false |
| Answer» C. | |
| 983. |
While finding correct location for saving key value pair, how many times key is hashed? |
| A. | 1 |
| B. | 2 |
| C. | 3 |
| D. | unlimited till bucket is found |
| Answer» C. 3 | |
| 984. |
What happens if we put a key object in a HashMap which exists? |
| A. | The new object replaces the older object |
| B. | The new object is discarded |
| C. | The old object is removed from the map |
| D. | It throws an exception as the key already exists in the map |
| Answer» B. The new object is discarded | |
| 985. |
What is the premise of equality for IdentityHashMap? |
| A. | Reference equality |
| B. | Name equality |
| C. | Hashcode equality |
| D. | Length equality |
| Answer» B. Name equality | |
| 986. |
Which of the below does not implement Map interface? |
| A. | HashMap |
| B. | Hashtable |
| C. | EnumMap |
| D. | Vector |
| Answer» E. | |
| 987. |
Map implements collection interface? |
| A. | True |
| B. | false |
| Answer» C. | |
| 988. |
What is the output of this program? class Output { public static void main(String args[]) { ArrayList obj = new ArrayList(); obj.add("A"); obj.add("D"); obj.ensureCapacity(3); obj.trimToSize(); System.out.println(obj.size()); } } |
| A. | 1 |
| B. | 2 |
| C. | 3 |
| D. | 4 |
| Answer» C. 3 | |
| 989. |
What is the output of this program? import java.util.*; class Output { public static void main(String args[]) { ArrayList obj = new ArrayList(); obj.add("A"); obj.ensureCapacity(3); System.out.println(obj.size()); } } |
| A. | 1 |
| B. | 2 |
| C. | 3 |
| D. | 4 |
| Answer» B. 2 | |
| 990. |
What is the output of this program? import java.util.*; class Output { public static void main(String args[]) { ArrayList obj = new ArrayList(); obj.add("A"); obj.add(0, "B"); System.out.println(obj.size()); } } |
| A. | 0 |
| B. | 1 |
| C. | 2 |
| D. | What is the output of this program? import java.util.*; class Output { public static void main(String args[]) { ArrayList obj = new ArrayList(); obj.add("A"); obj.add(0, "B"); System.out.println(obj.size()); } } |
| Answer» D. What is the output of this program? import java.util.*; class Output { public static void main(String args[]) { ArrayList obj = new ArrayList(); obj.add("A"); obj.add(0, "B"); System.out.println(obj.size()); } } | |
| 991. |
What is the output of this program? import java.util.*; class Arraylist { public static void main(String args[]) { ArrayList obj = new ArrayList(); obj.add("A"); obj.add("B"); obj.add("C"); obj.add(1, "D"); System.out.println(obj); } } |
| A. | [A, B, C, D]. |
| B. | [A, D, B, C]. |
| C. | [A, D, C]. |
| D. | [A, B, C]. |
| Answer» C. [A, D, C]. | |
| 992. |
Which of these method is used to reduce the capacity of an ArrayList object? |
| A. | trim() |
| B. | trimSize() |
| C. | trimTosize() |
| D. | trimToSize() |
| Answer» E. | |
| 993. |
Which of these methods can be used to obtain a static array from an ArrayList object? |
| A. | Array() |
| B. | covertArray() |
| C. | toArray() |
| D. | covertoArray() |
| Answer» D. covertoArray() | |
| 994. |
Which of these method of ArrayList class is used to obtain present size of an object? |
| A. | size() |
| B. | length() |
| C. | index() |
| D. | capacity() |
| Answer» B. length() | |
| 995. |
Which of these method can be used to increase the capacity of ArrayList object manually? |
| A. | Capacity() |
| B. | increaseCapacity() |
| C. | increasecapacity() |
| D. | ensureCapacity() |
| Answer» E. | |
| 996. |
Which of these class can generate an array which can increase and decrease in size automatically? |
| A. | ArrayList() |
| B. | DynamicList() |
| C. | LinkedList() |
| D. | MallocList() |
| Answer» B. DynamicList() | |
| 997. |
Which of these standard collection classes implements a dynamic array? |
| A. | AbstractList |
| B. | LinkedList |
| C. | ArrayList |
| D. | AbstractSet |
| Answer» D. AbstractSet | |
| 998. |
Which API gets the SocketAddress (usually IP address + port number) of the remote host that this packet is being sent to or is coming from. |
| A. | getSocketAddress() |
| B. | getAddress() |
| C. | address() |
| D. | none of the mentioned |
| Answer» B. getAddress() | |
| 999. |
Which of these is a return type of getAddress() method of DatagramPacket class? |
| A. | DatagramPacket |
| B. | DatagramSocket |
| C. | InetAddress |
| D. | ServerSocket |
| Answer» D. ServerSocket | |
| 1000. |
Which of these method of DatagramPacket class is used to find the destination address? |
| A. | findAddress() |
| B. | findAddress() |
| C. | Address() |
| D. | whois() |
| Answer» C. Address() | |