Unit 6 - Practice Quiz

CSE310 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the primary advantage of using generics (e.g., ArrayList<String>) in Java Collections?

Creating a collection by using generics Easy
A. To allow collections to store primitive types like int directly.
B. To provide compile-time type safety and avoid ClassCastException.
C. To increase the runtime speed of the collection.
D. To make the collection automatically sorted.

2 Which of the following is the correct syntax to create an ArrayList that can only hold Integer objects?

Creating a collection by using generics Easy
A. ArrayList(Integer) list = new ArrayList();
B. ArrayList<int> list = new ArrayList<int>();
C. ArrayList list = new ArrayList<Integer>();
D. ArrayList<Integer> list = new ArrayList<>();

3 Which method is used to retrieve an element from an ArrayList at a specific index?

Implementing an ArrayList Easy
A. get(int index)
B. fetch(int index)
C. retrieve(int index)
D. element(int index)

4 Which statement about ArrayList is true?

Implementing an ArrayList Easy
A. Its size is fixed after creation.
B. It automatically sorts its elements.
C. It cannot contain duplicate elements.
D. It maintains the insertion order of elements.

5 What is the defining characteristic of a TreeSet?

Implementing TreeSet using Comparable and Comparator interfaces Easy
A. It stores elements in the order they were inserted.
B. It stores elements in a sorted order.
C. It stores key-value pairs.
D. It allows multiple null elements.

6 To enable natural sorting for a custom object in a TreeSet, which interface should the object's class implement?

Implementing TreeSet using Comparable and Comparator interfaces Easy
A. Orderable
B. Comparator
C. Sortable
D. Comparable

7 When would you use a Comparator instead of Comparable with a TreeSet?

Implementing TreeSet using Comparable and Comparator interfaces Easy
A. When you want to prevent sorting entirely.
B. When you want to store elements in insertion order.
C. When you want to define a custom sorting logic without modifying the element's class.
D. When the elements are primitive types.

8 A HashMap in Java is used to store data as:

Implementing a HashMap Easy
A. A stack of elements
B. Key-value pairs
C. A set of unique, sorted elements
D. A list of ordered elements

9 Which method is used to add or update an entry in a HashMap?

Implementing a HashMap Easy
A. add(K key, V value)
B. set(K key, V value)
C. put(K key, V value)
D. insert(K key, V value)

10 What does 'Deque' stand for?

Implementing a Deque Easy
A. Default Queue
B. Dynamic Execution Queue
C. Double Ended Queue
D. Data Entry Queue

11 Which of the following methods can be used to add an element to the end of a Deque?

Implementing a Deque Easy
A. addFirst()
B. addLast()
C. peek()
D. push()

12 What does JDBC stand for?

Introduction to JDBC Easy
A. Java Database Commands
B. Java Data Binding and Control
C. Joint Database Connection
D. Java Database Connectivity

13 What is the primary role of the java.sql.Connection interface in JDBC?

Introduction to JDBC Easy
A. To execute a SQL query.
B. To represent a session with a specific database.
C. To hold the results of a query.
D. To define the database URL.

14 What is the function of a JDBC Driver?

JDBC Drivers Easy
A. To manage the Java Virtual Machine (JVM).
B. To write the SQL queries for the programmer.
C. To translate JDBC API calls into the specific protocol of a database.
D. To create the database schema automatically.

15 Which class is commonly used to load a JDBC driver and establish a connection to a database?

JDBC Drivers Easy
A. SQLConnector
B. DriverLoader
C. ConnectionManager
D. DriverManager

16 In database terminology, what does the 'R' in CRUD stand for?

CRUD operation Using JDBC Easy
A. Remove
B. Register
C. Replace
D. Read

17 Which SQL statement corresponds to the 'Create' operation in CRUD?

CRUD operation Using JDBC Easy
A. UPDATE
B. INSERT
C. SELECT
D. CREATE TABLE

18 After executing a SELECT query in JDBC, which object is used to iterate through the returned rows?

CRUD operation Using JDBC Easy
A. ResultSet
B. RowSet
C. Statement
D. Connection

19 Which of the following is an example of a non-conventional or NoSQL database?

Connecting to non-conventional Databases Easy
A. MySQL
B. Oracle Database
C. MongoDB
D. PostgreSQL

20 How do Java applications typically connect to a NoSQL database like Redis or MongoDB?

Connecting to non-conventional Databases Easy
A. Using a JDBC-ODBC bridge.
B. Using a specific Java driver provided by the database vendor.
C. Using the standard Type 4 JDBC driver for all databases.
D. Java applications cannot connect to NoSQL databases.

21 Consider the following method. Which of the following method calls will result in a compile-time error?

java
public static void processElements(List<? extends Number> list) {
// method body
}

Creating a collection by using generics Medium
A. processElements(new ArrayList<Object>());
B. processElements(new ArrayList<Integer>());
C. processElements(new ArrayList<Double>());
D. processElements(new ArrayList<Number>());

22 What is the primary issue with the following code snippet?

java
List<String> stringList = new ArrayList<>();
List<Object> objectList = stringList; // Line 2
objectList.add(123);
String s = stringList.get(0);

Creating a collection by using generics Medium
A. It will throw a ClassCastException when stringList.get(0) is called.
B. The code runs without any errors and s will hold the string "123".
C. It will throw an ArrayStoreException at runtime.
D. It will cause a compile-time error at Line 2.

23 What will be the output of the following code snippet?

java
import java.util.ArrayList;
import java.util.List;

public class Test {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("A");
list.add("B");
list.add("C");
list.add(1, "D");
list.remove("B");
System.out.println(list);
}
}

Implementing an ArrayList Medium
A. [D, A, C]
B. [A, D, B, C]
C. An IndexOutOfBoundsException is thrown.
D. [A, D, C]

24 Which statement best describes the performance characteristics of adding an element to the beginning of a large ArrayList versus a large LinkedList?

Implementing an ArrayList Medium
A. Both have similar performance, approximately O(1).
B. ArrayList is faster because it uses a contiguous block of memory.
C. LinkedList is faster because it only requires updating a few node references.
D. ArrayList is faster because it avoids the overhead of node object creation.

25 Given the Employee class below, what is the result of executing the main method? The Employee class does not implement Comparable.

java
class Employee {
private int id;
public Employee(int id) { this.id = id; }
}

public class TestSet {
public static void main(String[] args) {
Set<Employee> employees = new TreeSet<>();
employees.add(new Employee(101));
employees.add(new Employee(102));
System.out.println(employees.size());
}
}

Implementing TreeSet using Comparable and Comparator interfaces Medium
A. The code compiles and prints 2.
B. The code compiles but throws a ClassCastException at runtime.
C. The code fails to compile because Employee is not Comparable.
D. The code compiles and prints 0.

26 What is the output of the following code?

java
import java.util.*;

class Product {
String name;
double price;
Product(String name, double price) {
this.name = name;
this.price = price;
}
@Override
public String toString() { return name; }
}

public class TestSort {
public static void main(String[] args) {
Comparator<Product> priceComparator = (p1, p2) -> Double.compare(p2.price, p1.price);
Set<Product> products = new TreeSet<>(priceComparator);
products.add(new Product("Laptop", 1200.0));
products.add(new Product("Mouse", 25.0));
products.add(new Product("Keyboard", 75.0));
System.out.println(products);
}
}

Implementing TreeSet using Comparable and Comparator interfaces Medium
A. [Mouse, Keyboard, Laptop]
B. [Laptop, Mouse, Keyboard]
C. [Laptop, Keyboard, Mouse]
D. The code will throw a ClassCastException.

27 Consider a Person class that implements Comparable by comparing ages. What happens if you add two different Person objects with the same age to a TreeSet<Person>?

java
// Assume Person class with name and age fields
// and compareTo implemented as:
public int compareTo(Person other) {
return Integer.compare(this.age, other.age);
}

// In main method:
Set<Person> personSet = new TreeSet<>();
personSet.add(new Person("Alice", 30));
personSet.add(new Person("Bob", 30));

Implementing TreeSet using Comparable and Comparator interfaces Medium
A. Both objects are added to the set successfully.
B. The behavior is undefined and depends on the JVM.
C. A RuntimeException is thrown because of the duplicate age.
D. Only the first object ("Alice", 30) is added to the set.

28 What will be printed to the console when the following code is executed?

java
import java.util.HashMap;
import java.util.Map;

public class MapTest {
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<>();
map.put("A", 1);
map.put("B", 2);
Integer oldValue = map.put("A", 3);
map.put(null, 4);
map.put("C", null);

System.out.println(oldValue + "," + map.size());
}
}

Implementing a HashMap Medium
A. 1,4
B. 3,5
C. null,5
D. 1,5

29 You have a custom class Student that you want to use as a key in a HashMap. If you only override the equals() method but not the hashCode() method, what is the most likely consequence?

java
// Assume Student class has id and name
// and equals() is correctly overridden based on id.
// hashCode() is NOT overridden.
Map<Student, String> grades = new HashMap<>();
Student s1 = new Student(1, "Alice");
Student s2 = new Student(1, "Alice"); // s1.equals(s2) is true
grades.put(s1, "A");
System.out.println(grades.get(s2));

Implementing a HashMap Medium
A. The program will throw a RuntimeException.
B. The program will print "A".
C. The program will fail to compile.
D. The program will most likely print null.

30 What is the output of this code snippet?

java
import java.util.HashMap;

public class Test {
public static void main(String[] args) {
HashMap<Integer, String> map = new HashMap<>();
map.put(1, "One");
map.put(2, "Two");
map.put(3, "One");

map.compute(1, (k, v) -> v.concat("Plus"));
map.computeIfAbsent(4, k -> "Four");
map.computeIfPresent(2, (k, v) -> null);

System.out.println(map);
}
}

Implementing a HashMap Medium
A. A NullPointerException is thrown.
B. {1=OnePlus, 3=One, 4=Four}
C. {1=OnePlus, 2=Two, 3=One, 4=Four}
D. {1=OnePlus, 2=null, 3=One, 4=Four}

31 What is the final content of the deque and what is printed after executing the following code?

java
import java.util.ArrayDeque;
import java.util.Deque;

public class DequeTest {
public static void main(String[] args) {
Deque<Integer> deque = new ArrayDeque<>();
deque.push(10);
deque.offerLast(20);
deque.push(30);
deque.offerFirst(40);
System.out.print(deque.pollFirst() + ",");
System.out.print(deque.pop());
}
}

Implementing a Deque Medium
A. 40,30
B. 40,10
C. 10,20
D. 30,40

32 You need to implement a Last-In-First-Out (LIFO) stack data structure with a fixed capacity. If you use an ArrayDeque, which pair of methods should you use to add and remove elements to ensure that an exception is thrown if the operation cannot be completed (e.g., adding to a full stack)?

Implementing a Deque Medium
A. addFirst() and removeFirst()
B. add() and remove()
C. offer() and poll()
D. offerFirst() and pollFirst()

33 A Java application deployed on a client machine needs to connect to a corporate database. The client machine does not have any vendor-specific database libraries installed. A middle-tier application server is used to proxy database requests. Which type of JDBC driver is being described?

JDBC Drivers Medium
A. Type 2: Native-API Driver
B. Type 4: Thin Driver
C. Type 1: JDBC-ODBC Bridge
D. Type 3: Network-Protocol Driver

34 What is the primary advantage of using a Type 4 JDBC driver over a Type 2 driver for a standalone Java application that needs to be easily deployable on different operating systems?

JDBC Drivers Medium
A. Type 4 drivers are written in 100% pure Java and are platform-independent.
B. Type 4 drivers provide better support for SQL-92 standards.
C. Type 4 drivers offer superior performance.
D. Type 4 drivers require an ODBC data source to be configured on the client machine.

35 What does the integer value returned by the executeUpdate() method of a PreparedStatement typically represent when executing an UPDATE or DELETE statement?

CRUD operation Using JDBC Medium
A. The auto-generated key of the modified record.
B. The number of rows in the table that were affected by the execution.
C. The total number of rows in the table after the operation.
D. A status code indicating success (1) or failure (0).

36 Examine the following JDBC code snippet intended to prevent SQL injection. Which statement is most accurate?

java
String userInput = "' OR '1'='1";
String query = "SELECT * FROM users WHERE username = '" + userInput + "' AND status = 'active'";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(query);

CRUD operation Using JDBC Medium
A. This code is safe because the executeQuery method automatically sanitizes input.
B. This code is vulnerable to SQL injection; it should use PreparedStatement instead.
C. This code correctly uses a Statement and is safe from SQL injection.
D. This code will throw a SQLException because of the special characters in userInput.

37 Consider the following JDBC transaction management code. Assuming the DELETE statement is valid and affects 5 rows, what will be the state of the employees table after this code executes?

java
Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
try {
conn.setAutoCommit(false); // Start transaction
Statement stmt = conn.createStatement();
stmt.executeUpdate("DELETE FROM employees WHERE department = 'Sales'");
conn.rollback(); // Roll back the transaction
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
}

CRUD operation Using JDBC Medium
A. The transaction will be in a pending state and will need to be manually committed later.
B. The employees table will be in its original state, as if the DELETE never happened.
C. An SQLException will be thrown when commit() is called after rollback().
D. The 5 rows from the 'Sales' department will be permanently deleted.

38 When retrieving data from a ResultSet, what is the consequence of calling rs.getString("column_name") for a column that has a SQL NULL value?

CRUD operation Using JDBC Medium
A. It throws a SQLException indicating no data is available.
B. It throws a NullPointerException.
C. It returns a null reference.
D. It returns the empty string "".

39 Which of the following is a critical difference when establishing a JDBC connection to a NoSQL database (like Apache Cassandra) versus a traditional RDBMS (like PostgreSQL)?

Connecting to non-conventional Databases Medium
A. PreparedStatement cannot be used with NoSQL databases due to the lack of a structured query language.
B. The java.sql.Connection interface is completely replaced by a vendor-specific interface.
C. NoSQL databases do not support the concept of transactions, so connection.setAutoCommit(false) will always fail.
D. The JDBC URL format and the specific driver class name are unique to the NoSQL database's JDBC driver.

40 What is the primary role of the java.sql.DriverManager class in the JDBC API?

Introduction to JDBC Medium
A. To establish a connection to a database by selecting an appropriate driver from the list of registered drivers.
B. To execute SQL queries and return a ResultSet.
C. To provide metadata about the database, such as table names and column types.
D. To represent a specific database connection and manage transactions.

41 Consider a custom class Employee used as a key in a HashMap. The hashCode() method is correctly implemented, but the equals() method is mistakenly left as the default implementation from Object (i.e., this == obj). What is the primary consequence of this flawed implementation when two distinct Employee objects with identical content (and thus identical hash codes) are used?

Implementing a HashMap Hard
A. The second put() operation will add a new entry, and the map will contain two separate entries for logically equivalent keys, potentially in the same bucket.
B. A RuntimeException will be thrown during the second put() operation due to the violation of the hashCode-equals contract.
C. Both objects will be stored in the HashMap in the same bucket, likely in a linked list or tree node, and get() will retrieve the first one inserted.
D. The second put() operation with a logically equivalent but distinct key object will overwrite the first entry.

42 A TreeSet is created for a custom Product class. The Product class implements Comparable<Product> such that compareTo() only considers the product's price. What is the result of adding two different Product objects with the same price but different names to this TreeSet?

Implementing TreeSet using Comparable and Comparator interfaces Hard
A. Only the first product is added; the add() call for the second product returns false.
B. The behavior is undefined and depends on the JVM implementation.
C. Both products are added successfully as they are different objects.
D. A ClassCastException is thrown because compareTo() is inconsistent with equals().

43 You are executing a batch update using PreparedStatement.executeBatch(). The batch contains 100 SQL statements. The 50th statement fails due to a unique constraint violation. Assuming the JDBC driver supports batch update exceptions and there's no explicit transaction management (autoCommit is true), what is the state of the database and the return value of the method?

CRUD operation Using JDBC Hard
A. A BatchUpdateException is thrown. The first 49 statements are successfully committed, and the rest are not executed.
B. The method returns an array of 100 integers, with the 50th element being Statement.EXECUTE_FAILED, and all other successful statements are committed.
C. A standard SQLException is thrown, and the transaction is automatically rolled back, leaving the database unchanged.
D. A BatchUpdateException is thrown, and none of the 100 statements are committed to the database.

44 Analyze the following Java code. Why does the last line fail to compile?

java
List<String> ls = new ArrayList<>();
List<? extends Object> lo = ls;
// lo.add("Hello"); // This line fails to compile

Creating a collection by using generics Hard
A. Because lo is immutable and cannot be modified.
B. Because of type erasure, the compiler cannot guarantee that adding a String is type-safe.
C. Because the wildcard ? extends Object makes the list a producer (readable), but not a consumer (writable), except for null.
D. Because List<? extends Object> is equivalent to List<Object>, and a List<String> cannot be assigned to it without an explicit cast.

45 In a cloud-native microservices architecture where services are deployed in Docker containers, which JDBC driver type is almost universally preferred and why?

JDBC Drivers Hard
A. Type 3 (Network-Protocol Driver), because it allows for a middle-tier server to handle database connections, improving security.
B. Type 1 (JDBC-ODBC Bridge), because it provides maximum compatibility with legacy systems.
C. Type 4 (Database-Protocol Driver), because it is a self-contained, platform-independent pure Java driver, simplifying deployment and eliminating native dependencies.
D. Type 2 (Native-API Driver), because it offers the highest performance by using native database libraries.

46 An ArrayList is created with an initial capacity of 10. You then add 10 elements. What happens internally when you attempt to add the 11th element, and what is the amortized time complexity of adding N elements one by one to an initially empty ArrayList?

Implementing an ArrayList Hard
A. A new array, typically of size 15 (old capacity * 1.5), is created, and all 10 old elements are copied over. The amortized time complexity is .
B. The ArrayList is converted to a LinkedList to accommodate the new element. The amortized time complexity is .
C. A new array, typically of size 15 (old capacity * 1.5), is created, and all 10 old elements are copied over. The amortized time complexity is .
D. A new array of size 11 is created, and all 10 old elements are copied over. The amortized time complexity is .

47 You need a data structure that can function as a LIFO stack but must also provide capacity-restriction without throwing an exception upon failure. Which Deque implementation and method should you use to add elements?

Implementing a Deque Hard
A. LinkedBlockingDeque and the offerFirst() method.
B. ArrayDeque and the addFirst() method.
C. LinkedList and the addFirst() method.
D. ArrayDeque and the push() method.

48 Consider a JDBC transaction set to TRANSACTION_SERIALIZABLE isolation level. A long-running transaction (T1) reads all employees in the 'sales' department. While T1 is still active, another transaction (T2) attempts to insert a new employee into the 'sales' department and commit. What is the most likely outcome?

CRUD operation Using JDBC Hard
A. T2 will commit successfully, but T1 will not see the new employee, even if it re-queries, thus preventing a phantom read.
B. T2 will be blocked until T1 completes (either commits or rolls back).
C. T2 commits successfully, and a subsequent read by T1 within the same transaction will see the new employee (a phantom read).
D. T1 will immediately throw a SQLException because its result set has been invalidated by T2's insert.

49 What is the key difference between the state of an ArrayList after calling trimToSize() versus clear()?

Implementing an ArrayList Hard
A. trimToSize() removes all elements and sets capacity to 0; clear() only sets the size to 0 but keeps the internal array.
B. Both methods set the size to 0, but trimToSize() deallocates the internal array while clear() fills it with null values.
C. trimToSize() has no effect if capacity equals size; clear() replaces the internal array with a new empty array.
D. trimToSize() sets the capacity to the current size; clear() sets the size to 0 but leaves the capacity unchanged.

50 When using a JDBC driver for a key-value store like Redis, which JDBC concept is the most difficult to map meaningfully and is often implemented with significant limitations?

Connecting to non-conventional Databases Hard
A. Complex cross-key transactions with ACID properties.
B. Multi-row result sets from a single query (ResultSet).
C. Executing simple key lookups (PreparedStatement with WHERE key = ?).
D. Connection Management (DriverManager, DataSource).

51 Given the following code, what is the output?
java
class Person {
int id;
public Person(int id) { this.id = id; }
@Override public int hashCode() { return id; }
// equals() is NOT overridden
}

Set<Person> set = new HashSet<>();
set.add(new Person(1));
set.add(new Person(1));

TreeSet<Person> treeSet = new TreeSet<>(Comparator.comparingInt(p -> p.id));
treeSet.addAll(set);

System.out.println(treeSet.size());

Implementing TreeSet using Comparable and Comparator interfaces Hard
A. 0
B. 1
C. 2
D. A RuntimeException is thrown.

52 In Java 8, HashMap buckets convert from a linked list to a balanced tree (specifically, a red-black tree) when the number of nodes in a bucket reaches a certain threshold. What is the primary reason for this change and under what condition does it occur?

Implementing a HashMap Hard
A. To handle null keys more efficiently; this occurs when a bucket containing a null key exceeds TREEIFY_THRESHOLD (default 8).
B. To save memory; this occurs when TREEIFY_THRESHOLD (default 8) is reached and map capacity is at least 64.
C. To improve worst-case performance from to for bucket operations; this occurs when TREEIFY_THRESHOLD (default 8) is reached AND the map's total capacity is at least MIN_TREEIFY_CAPACITY (default 64).
D. To improve worst-case performance from to for bucket operations; this occurs as soon as the bucket size exceeds TREEIFY_THRESHOLD (default 8).

53 You create a PreparedStatement from a Connection object and then execute it 1000 times with different parameters in a loop. Separately, you create a Statement object and execute 1000 different SQL queries by concatenating strings in a loop. Why is the PreparedStatement approach significantly more performant, especially in a client-server database model?

CRUD operation Using JDBC Hard
A. PreparedStatement uses a more optimized network protocol than Statement.
B. PreparedStatement is faster because it prevents SQL injection, which has a high-performance overhead.
C. PreparedStatement sends the query to the database only once; subsequent executions only send the new parameter values.
D. PreparedStatement automatically batches the requests, sending all 1000 at once.

54 Consider an ArrayDeque<Integer>. What is the fundamental difference in behavior and outcome between calling remove() on an empty deque versus calling poll() on an empty deque?

Implementing a Deque Hard
A. Both throw a NoSuchElementException.
B. remove() returns null, while poll() throws a NoSuchElementException.
C. remove() throws a NoSuchElementException, while poll() returns null.
D. Both return null.

55 Given the following two method signatures in a class, what is the outcome?

java
public void process(List<String> list) { / ... / }
public void process(List<Integer> list) { / ... / }

Creating a collection by using generics Hard
A. The code compiles, but at runtime, a ClassCastException will be thrown when either method is called.
B. The code compiles only if one of the methods is declared static.
C. The code fails to compile due to a clash, as type erasure removes the generic type information, making both signatures identical to the JVM.
D. The code compiles successfully, and method overloading works as expected based on the list's type.

56 In a modern, high-concurrency enterprise application, why is obtaining database connections via a DataSource object overwhelmingly preferred over using the traditional DriverManager.getConnection() method?

Introduction to JDBC Hard
A. DataSource implementations typically provide connection pooling, which is crucial for performance and scalability by reusing existing connections.
B. DataSource allows for connecting to non-conventional databases, which DriverManager does not support.
C. DataSource is part of the newer JDBC 4.0 specification, while DriverManager is deprecated.
D. DataSource provides a standardized way to handle different JDBC driver types, whereas DriverManager requires manual driver loading.

57 What happens if you obtain a subList from an ArrayList and then add an element to the original list?

Implementing an ArrayList Hard
A. A ConcurrentModificationException will be thrown immediately upon modifying the original list.
B. Any subsequent attempt to access the subList (e.g., get(), size(), iterator()) will result in a ConcurrentModificationException.
C. The subList is unaffected as it is a copy of the original elements.
D. The subList view is updated to reflect the new element if it falls within its range.

58 A HashMap is created with the default load factor (0.75) and default initial capacity (16). At what point will the map first trigger a resize operation?

Implementing a HashMap Hard
A. When the 13th element is added.
B. When the 16th element is added.
C. When the 17th element is added.
D. When the 12th element is added.

59 When creating a Statement, you can specify ResultSet.TYPE_SCROLL_SENSITIVE. What does this constant primarily enable and what is its major performance trade-off?

CRUD operation Using JDBC Hard
A. It allows bidirectional iteration over the ResultSet and makes it sensitive to changes (updates, deletes, inserts) made by other transactions after the ResultSet was created. It can be very resource-intensive for the database and driver.
B. It creates a static snapshot of the data at the time of the query, preventing any updates from being seen. It has low performance overhead.
C. It enables the ResultSet to see updates and deletes made by others but not inserts (preventing phantom reads). It has moderate performance overhead.
D. It allows the ResultSet to be updated, but it is not sensitive to changes made by other transactions. It has high performance.

60 A class Point has a compareTo method that is not transitive. Specifically, p1.compareTo(p2) > 0, p2.compareTo(p3) > 0, but p1.compareTo(p3) < 0. What is the likely result of adding these three points to a TreeSet?

Implementing TreeSet using Comparable and Comparator interfaces Hard
A. The code will compile and run, but the internal red-black tree structure of the TreeSet will be corrupted, leading to undefined behavior on subsequent operations like contains() or remove().
B. The add method for p3 will return false as it will be considered a duplicate of p1.
C. The TreeSet will contain all three points in a stable, predictable order.
D. An IllegalArgumentException or ClassCastException might be thrown during one of the insertions.