MauryaHub PYQ Practice

Programming Concepts using Java · Quiz 2 · Sep 2024

Programming Concepts using Java · Quiz 2 · Sep 2024

← Course papers · Start practice / exam

This page contains the reliably extracted subset, not the complete original paper.

Questions and published explanations below are available without starting a test. Some questions may not have a published solution yet.

16 / 16 published solutions

Question 79 MCQ · 2.0 marks

Source diagram or notation
6406533457340.
A is positive definite.
6406533457341.
A is positive semi-definite.
6406533457342.
A is negative definite.
6406533457343.
A is negative semi-definite.       **Java** **Section Id :** 64065373860 **Section Number :** 6 **Section type :** Online **Mandatory or Optional :** Mandatory **Number of Questions :** 16 **Number of Questions to be attempted :** 16 **Section Marks :** 100 **Display Number Panel :** Yes **Section Negative Marks :** 0 **Group All Questions :** No **Enable Mark as Answered Mark for Review and** No **Clear Response :** **Section Maximum Duration :** 0 **Section Minimum Duration :** 0 **Section Time In :** Minutes **Maximum Instruction Time :** 0

Published solution

**Answer: B** **Topic:** Linear Algebra — *Positive Semi-Definiteness of a Singular 2x2 Symmetric Matrix* ### Step-by-Step Solution **Step 1:** Examine the symmetric matrix $A = \begin{pmatrix} 1 & 4 \\ 4 & 16 \end{pmatrix}$ by computing its trace and determinant (or eigenvalues): - $\text{tr}(A) = 1 + 16 = 17 > 0$ - $\det(A) = (1)(16) - (4)(4) = 16 - 16 = 0$ **Step 2:** Since $\lambda_1 + \lambda_2 = 17$ and $\lambda_1 \lambda_2 = 0$, the eigenvalues of $A$ are $\lambda_1 = 17 > 0$ and $\lambda_2 = 0$. **Step 3:** Because all eigenvalues are **non-negative** ($\lambda_i \ge 0$) with at least one zero eigenvalue, $A$ is **positive semi-definite** (**B**). **Key Takeaway / Tip:** Equivalently, $x^T A x = x_1^2 + 8x_1 x_2 + 16x_2^2 = (x_1 + 4x_2)^2 \ge 0$ for all $x \in \mathbb{R}^2$, which equals $0$ along the line $x_1 = -4x_2$, proving $A$ is positive semi-definite. A: **Incorrect:** Option A (A is positive definite.) does not satisfy the conditions derived in the step-by-step analysis for Positive Semi-Definiteness of a Singular 2x2 Symmetric Matrix (correct choice: B). B: **Correct:** Option B (A is positive semi-definite.) matches our derived result under Positive Semi-Definiteness of a Singular 2x2 Symmetric Matrix. Equivalently, $x^T A x = x_1^2 + 8x_1 x_2 + 16x_2^2 = (x_1 + 4x_2)^2 \ge 0$ for all $x \in \mathbb{R}^2$, which equals $0$ along the line $x_1 = -4x_2$, proving $A$ is positive semi-definite. C: **Incorrect:** Option C (A is negative definite.) does not satisfy the conditions derived in the step-by-step analysis for Positive Semi-Definiteness of a Singular 2x2 Symmetric Matrix (correct choice: B). D: **Incorrect:** Option D (A is negative semi-definite.       **Java** **Section Id :** 64065373860 **Section Number :** 6 **Section type :** Online **Mandatory or Optional :** Mandatory **Number of Quest...) does not satisfy the conditions derived in the step-by-step analysis for Positive Semi-Definiteness of a Singular 2x2 Symmetric Matrix (correct choice: B).

Report a correction for Q79

Question 81 MCQ · 6.0 marks

Source diagram or notation
6406533457346.Source diagram or notation
6406533457347.Source diagram or notation
6406533457348.Source diagram or notation
6406533457349.Source diagram or notation

Published solution

**Answer: C** **Topic:** Java Generics — *Upper-Bounded Wildcards in Generic Collections* ### Step-by-Step Solution **Step 1:** In `main()`, `printPrice` is called twice: 1. `printPrice(d)` where `d` has type `List<Dell>` (`Dell extends Laptop`). 2. `printPrice(h)` where `h` has type `List<HP>` (`HP extends Laptop`). **Step 2:** Recall that in Java, generics are **invariant**: neither `List<Dell>` nor `List<HP>` is a subtype of `List<Laptop>` (Option A fails) or `List<Object>` (Option D fails), and `List<HP>` cannot accept `List<Dell>` (Option B fails). **Step 3:** To accept a `List` of **any subtype of `Laptop`** and safely call `.get(i).getPrice()`, we use an **upper-bounded wildcard**: `public static void printPrice(List<? extends Laptop> lst)` **Step 4:** This matches Option **C**. **Key Takeaway / Tip:** Use `List<? extends Laptop>` (upper-bounded wildcard) whenever a method reads elements as `Laptop` instances from lists of different `Laptop` subclasses (`List<Dell>`, `List<HP>`). A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Upper-Bounded Wildcards in Generic Collections (correct choice: C). B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Upper-Bounded Wildcards in Generic Collections (correct choice: C). C: **Correct:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Upper-Bounded Wildcards in Generic Collections. Use `List<? extends Laptop>` (upper-bounded wildcard) whenever a method reads elements as `Laptop` instances from lists of different `Laptop` subclasses (`List<Dell>`, `List<HP>`). D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Upper-Bounded Wildcards in Generic Collections (correct choice: C).

Report a correction for Q81

Question 82 MCQ · 6.0 marks

Source diagram or notation
6406533457350.Source diagram or notation
6406533457351.Source diagram or notation
6406533457352.Source diagram or notation
6406533457353.Source diagram or notation

Published solution

**Answer: C** **Topic:** Object-Oriented Programming in Java — *Interface Reference Types and Method Visibility* ### Step-by-Step Solution **Step 1:** In the code, `class Headphone implements Purchasable, Reviewable`, where `purchase()` is in `Purchasable` and `review()` is in `Reviewable`. **Step 2:** In `main()`, `Purchasable p1 = new Headphone();` declares `p1` with compile-time type **`Purchasable`**: - `p1.purchase();` compiles because `purchase()` is declared in `Purchasable`. - `p1.review();` **fails to compile** because the interface `Purchasable` does not declare a `review()` method! **Step 3:** Therefore, **C** (`This program generates compiler error because p1 of type Purchasable cannot invoke method review()`) is correct. **Key Takeaway / Tip:** Even when a class implements multiple interfaces (`Purchasable` and `Reviewable`), a reference typed as `Purchasable` can only invoke methods declared in `Purchasable`. A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Interface Reference Types and Method Visibility (correct choice: C). B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Interface Reference Types and Method Visibility (correct choice: C). C: **Correct:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Interface Reference Types and Method Visibility. Even when a class implements multiple interfaces (`Purchasable` and `Reviewable`), a reference typed as `Purchasable` can only invoke methods declared in `Purchasable`. D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Interface Reference Types and Method Visibility (correct choice: C).

Report a correction for Q82

Question 83 MCQ · 6.0 marks

Source diagram or notation
6406533457378.Source diagram or notation
6406533457379.Source diagram or notation
6406533457380.Source diagram or notation
6406533457381.Source diagram or notation

Published solution

**Answer: B** **Topic:** Java Collections Framework — *Natural Alphabetical Ordering in TreeSet and TreeMap* ### Step-by-Step Solution **Step 1:** In `Olympics`, `t1` (medalists with `medals > 0`) and `t2` (non-medalists with `medals == 0`) are both **`TreeSet<String>`** instances. **Step 2:** Classify the 5 athletes inserted into `medals`: - **Medalists (`medals > 0` $\to$ `t1`)**: `"Bolt"` (2), `"Manu"` (1), `"Gulan"` (3). - **Non-Medalists (`medals == 0` $\to$ `t2`)**: `"Sindhu"` (0), `"Rahul"` (0). **Step 3:** Because `TreeSet<String>` automatically maintains its elements in **natural (alphabetical/lexicographical) sorted order**: - `t1` sorts `"Bolt", "Manu", "Gulan"` alphabetically as **`[Bolt, Gulan, Manu]`**. - `t2` sorts `"Sindhu", "Rahul"` alphabetically as **`[Rahul, Sindhu]`**. **Step 4:** This exact output matches Option **B**. **Key Takeaway / Tip:** `TreeSet` and `TreeMap` always iterate over elements in natural sorted order (`Comparable`), not insertion order. A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Natural Alphabetical Ordering in TreeSet and TreeMap (correct choice: B). B: **Correct:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Natural Alphabetical Ordering in TreeSet and TreeMap. `TreeSet` and `TreeMap` always iterate over elements in natural sorted order (`Comparable`), not insertion order. C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Natural Alphabetical Ordering in TreeSet and TreeMap (correct choice: B). D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Natural Alphabetical Ordering in TreeSet and TreeMap (correct choice: B).

Report a correction for Q83

Question 84 MCQ · 6.0 marks

Source diagram or notation
6406533457398.Source diagram or notation
6406533457399.Source diagram or notation
6406533457400.Source diagram or notation
6406533457401.Source diagram or notation

Published solution

**Answer: B** **Topic:** Java Collections Framework — *Insertion Order and Key Updating in LinkedHashMap* ### Step-by-Step Solution **Step 1:** `LinkedHashMap<String, Integer>` maintains keys in their **first-insertion order**, and updating an existing key's value via `map.put(key, newVal)` **preserves its original position** in the iteration order. **Step 2:** Trace the 4 `stockList` entries in `printStocks`: 1. `("AAPL", 1500)`: inserts key `"AAPL"` $\to 1500$. (Order: `AAPL`) 2. `("MSFT", 2000)`: inserts key `"MSFT"` $\to 2000$. (Order: `AAPL, MSFT`) 3. `("GOOGL", 1200)`: inserts key `"GOOGL"` $\to 1200$. (Order: `AAPL, MSFT, GOOGL`) 4. `("AAPL", 800)`: updates existing key `"AAPL"` to `1500 + 800 = 2300` while keeping `"AAPL"` first! **Step 3:** Printing the entries in `LinkedHashMap` order outputs: `AAPL = 2300` `MSFT = 2000` `GOOGL = 1200` which matches **B**. **Key Takeaway / Tip:** In `LinkedHashMap`, re-inserting an existing key updates its value (`1500 + 800 = 2300`) without changing its insertion-order position. A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Insertion Order and Key Updating in LinkedHashMap (correct choice: B). B: **Correct:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Insertion Order and Key Updating in LinkedHashMap. In `LinkedHashMap`, re-inserting an existing key updates its value (`1500 + 800 = 2300`) without changing its insertion-order position. C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Insertion Order and Key Updating in LinkedHashMap (correct choice: B). D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Insertion Order and Key Updating in LinkedHashMap (correct choice: B).

Report a correction for Q84

Question 85 MSQ · 6.0 marks

Source diagram or notation
6406533457354.Source diagram or notation
6406533457355.Source diagram or notation
6406533457356.Source diagram or notation
6406533457357.Source diagram or notation

Published solution

**Answer: B, D** **Topic:** Java Generics — *Generic Method Declarations and Polymorphic Array Parameters* ### Step-by-Step Solution **Step 1:** In `main()`, `Buyer[] cust = { new GoldCustomer(90000), new SilverCustomer(60000), new GoldCustomer(45000) };` creates an array of static type **`Buyer[]`**. **Step 2:** Check each candidate method header for `printHighestPurchase` (called with `cust`): - **A (`printHighestPurchase(<?> cust)`)**: Invalid Java syntax (wildcards `?` cannot be used as bare parameter types or array types without a generic class like `List<?>`). - **B (`public static <T extends Buyer> void printHighestPurchase(T[] cust)`)**: Valid generic method declaration where `T` is inferred as `Buyer` — **Correct!** - **C (`public static <T extends GoldCustomer> void printHighestPurchase(T[] cust)`)**: Fails to compile when passed `Buyer[]` because `Buyer` does not extend `GoldCustomer`. - **D (`public static void printHighestPurchase(Buyer[] cust)`)**: Directly accepts a `Buyer[]` array parameter — **Correct!** **Step 3:** Therefore, **B and D** are correct. **Key Takeaway / Tip:** An array of interface type `Buyer[]` can be accepted either directly as `Buyer[] cust` (D) or via a bounded type parameter `<T extends Buyer> void method(T[] cust)` (B). A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Generic Method Declarations and Polymorphic Array Parameters (correct choice: B, D). B: **Correct:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Generic Method Declarations and Polymorphic Array Parameters. An array of interface type `Buyer[]` can be accepted either directly as `Buyer[] cust` (D) or via a bounded type parameter `<T extends Buyer> void method(T[] cust)` (B). C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Generic Method Declarations and Polymorphic Array Parameters (correct choice: B, D). D: **Correct:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Generic Method Declarations and Polymorphic Array Parameters. An array of interface type `Buyer[]` can be accepted either directly as `Buyer[] cust` (D) or via a bounded type parameter `<T extends Buyer> void method(T[] cust)` (B).

Report a correction for Q85

Question 86 MCQ · 7.0 marks

Source diagram or notation
6406533457358.Source diagram or notation
6406533457359.Source diagram or notation
6406533457360.Source diagram or notation
6406533457361.Source diagram or notation

Published solution

**Answer: A** **Topic:** Java Exception Handling — *Custom Checked Exceptions and try-catch Control Flow* ### Step-by-Step Solution **Step 1:** Trace the `try` block in `main()`: 1. `obj1 = new User("Jimmy", 1)` has `accessStatus = 1` ($\ne 0$). Calling `obj1.checkPermission()` enters the `else` branch and prints **`Access enabled`**. 2. `obj2 = new User("Amritha", 0)` has `accessStatus = 0`. Calling `obj2.checkPermission()` throws `new AccessDeniedException("Access denied")`. 3. The `catch (AccessDeniedException e)` block catches the exception and executes `System.out.println("Error: " + e.getMessage());`, where `e.getMessage()` returns `"Access denied"`, printing **`Error: Access denied`**. **Step 2:** This two-line output (`Access enabled` followed by `Error: Access denied`) matches Option **A**. **Key Takeaway / Tip:** Passing `message` to `super(message)` in the custom `AccessDeniedException` constructor stores the string so `e.getMessage()` returns `"Access denied"`. A: **Correct:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Custom Checked Exceptions and try-catch Control Flow. Passing `message` to `super(message)` in the custom `AccessDeniedException` constructor stores the string so `e.getMessage()` returns `"Access denied"`. B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Custom Checked Exceptions and try-catch Control Flow (correct choice: A). C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Custom Checked Exceptions and try-catch Control Flow (correct choice: A). D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Custom Checked Exceptions and try-catch Control Flow (correct choice: A).

Report a correction for Q86

Question 87 MCQ · 7.0 marks

Source diagram or notation
6406533457362.Source diagram or notation
6406533457363.Source diagram or notation
6406533457364.Source diagram or notation
6406533457365.Source diagram or notation

Published solution

**Answer: D** **Topic:** Java Access Modifiers — *Same-Package Subclass Access (default, private, protected, public)* ### Step-by-Step Solution **Step 1:** Both `class A` and `class B extends A` are in the **same package** (`package com.pack1;`). Recall which access modifiers in `A` are accessible from `B` in the same package: - `LINE 1` (`methodOne()` — **default / package-private**): Accessible within the same package `com.pack1` $\implies$ Compiles. - `LINE 2` (`methodTwo()` — **`private`**): Accessible **only** inside `class A` itself $\implies$ **Compilation error!** - `LINE 3` (`methodThree()` — **`protected`**): Accessible within the same package and in subclasses $\implies$ Compiles. - `LINE 4` (`methodFour()` — **`public`**): Accessible everywhere $\implies$ Compiles. **Step 2:** Therefore, **Only LINE 2 generates a compilation error** (**D**). **Key Takeaway / Tip:** A `private` method is never accessible outside its declaring class—not even from a subclass in the same package. A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Same-Package Subclass Access (default, private, protected, public) (correct choice: D). B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Same-Package Subclass Access (default, private, protected, public) (correct choice: D). C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Same-Package Subclass Access (default, private, protected, public) (correct choice: D). D: **Correct:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Same-Package Subclass Access (default, private, protected, public). A `private` method is never accessible outside its declaring class—not even from a subclass in the same package.

Report a correction for Q87

Question 88 MCQ · 7.0 marks

Source diagram or notation
6406533457366.Source diagram or notation
6406533457367.Source diagram or notation
6406533457368.Source diagram or notation
6406533457369.Source diagram or notation

Published solution

**Answer: B** **Topic:** Java Assertions — *Tracing Java assert Statements with -ea Flag* ### Step-by-Step Solution **Step 1:** When `java -ea AssertTest` is executed (`-ea` enables assertions), trace `main()` step by step: 1. `salary = 120000; investments = 0;`. 2. **`assert-4`**: `assert salary > 0;` in `main()` evaluates `120000 > 0` (`true` $\implies$ passes). 3. Calls `computeTax(120000, 0)`: - **`assert-1`**: `assert salary > 0;` evaluates `120000 > 0` (`true` $\implies$ passes). - **`assert-2`**: `assert investments > 0;` evaluates `0 > 0`, which is **`false`**! **Step 2:** Therefore, **`assert-2`** is the first assertion that fails and throws an `AssertionError` (**B**). **Key Takeaway / Tip:** Trace the execution order starting from `main()`: `assert-4` runs first and passes, `assert-1` runs second and passes, and `assert-2` (`0 > 0`) runs third and throws `AssertionError`. A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Tracing Java assert Statements with -ea Flag (correct choice: B). B: **Correct:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Tracing Java assert Statements with -ea Flag. Trace the execution order starting from `main()`: `assert-4` runs first and passes, `assert-1` runs second and passes, and `assert-2` (`0 > 0`) runs third and throws `AssertionError`. C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Tracing Java assert Statements with -ea Flag (correct choice: B). D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Tracing Java assert Statements with -ea Flag (correct choice: B).

Report a correction for Q88

Question 89 MCQ · 7.0 marks

Source diagram or notation
6406533457370.Source diagram or notation
6406533457371.Source diagram or notation
6406533457372.Source diagram or notation
6406533457373.Source diagram or notation

Published solution

**Answer: B** **Topic:** Object-Oriented Programming in Java — *Downcasting Object[] Elements to a Common Interface* ### Step-by-Step Solution **Step 1:** In `class DeviceList`, `private Object[] pArr = {new Laptop(), new Tablet()};` stores `Laptop` and `Tablet` instances in an array of static type **`Object[]`**. - Both `Laptop` and `Tablet` implement the `Portable` interface (`void showportable()`). - Calling `pArr[i].showportable()` directly (Option A) fails to compile because `Object` has no `showportable()` method. - Casting to `(Laptop)` (Option C) or `(Tablet)` (Option D) throws a `ClassCastException` at runtime on the other device type! **Step 2:** Casting each element to their common interface **`((Portable)pArr[i]).showportable();`** (**B**) compiles cleanly and invokes each object's `showportable()` method. **Key Takeaway / Tip:** When an `Object[]` array holds heterogeneous classes (`Laptop` and `Tablet`) that share a common interface (`Portable`), cast to the interface `(Portable)` to avoid `ClassCastException`. A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Downcasting Object[] Elements to a Common Interface (correct choice: B). B: **Correct:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Downcasting Object[] Elements to a Common Interface. When an `Object[]` array holds heterogeneous classes (`Laptop` and `Tablet`) that share a common interface (`Portable`), cast to the interface `(Portable)` to avoid `ClassCastException`. C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Downcasting Object[] Elements to a Common Interface (correct choice: B). D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Downcasting Object[] Elements to a Common Interface (correct choice: B).

Report a correction for Q89

Question 90 MCQ · 7.0 marks

Source diagram or notation
6406533457374.Source diagram or notation
6406533457375.Source diagram or notation
6406533457376.Source diagram or notation
6406533457377.Source diagram or notation

Published solution

**Answer: B** **Topic:** Java Collections Framework — *Safe Element Removal During Iteration with Iterator.remove()* ### Step-by-Step Solution **Step 1:** While iterating over a `List<Book>` using an explicit `Iterator<Book> it = bookList.iterator();`: - Calling `bookList.remove(b)` directly on the collection (Option D) modifies the list outside the iterator and throws a `ConcurrentModificationException` on the next `it.next()` call. - `Iterator.remove()` takes **no arguments** (so `it.remove(b)` in Option A and `bookList.remove()` in Option C do not compile). **Step 2:** Calling **`it.remove()`** (**B**) safely removes the last element returned by `it.next()` from the underlying `bookList` without throwing `ConcurrentModificationException`. **Key Takeaway / Tip:** To remove elements safely while iterating with an `Iterator`, always use the zero-argument `it.remove()` method. A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Safe Element Removal During Iteration with Iterator.remove() (correct choice: B). B: **Correct:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Safe Element Removal During Iteration with Iterator.remove(). To remove elements safely while iterating with an `Iterator`, always use the zero-argument `it.remove()` method. C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Safe Element Removal During Iteration with Iterator.remove() (correct choice: B). D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Safe Element Removal During Iteration with Iterator.remove() (correct choice: B).

Report a correction for Q90

Question 91 MCQ · 7.0 marks

Source diagram or notation
6406533457382.Source diagram or notation
6406533457383.Source diagram or notation
6406533457384.Source diagram or notation
6406533457385.Source diagram or notation

Published solution

**Answer: D** **Topic:** Java Streams — *Filtering and Mapping an Integer Stream* ### Step-by-Step Solution **Step 1:** Trace the stream pipeline on `numbers = [2, 8, 5, 12, 15]`: 1. `.filter(n -> n % 2 == 0)`: keeps only the **even** numbers $\implies [2, 8, 12]$. 2. `.map(n -> n * 2)`: multiplies each remaining number by $2$ $\implies [4, 16, 24]$. 3. `.forEach(System.out::println)`: prints each number on its own line. **Step 2:** Thus, the output is `4`, `16`, `24`, which matches **D**. **Key Takeaway / Tip:** Filter removes odd numbers (`5` and `15`) first, and `map` doubles the remaining even numbers (`2 -> 4`, `8 -> 16`, `12 -> 24`). A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Filtering and Mapping an Integer Stream (correct choice: D). B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Filtering and Mapping an Integer Stream (correct choice: D). C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Filtering and Mapping an Integer Stream (correct choice: D). D: **Correct:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Filtering and Mapping an Integer Stream. Filter removes odd numbers (`5` and `15`) first, and `map` doubles the remaining even numbers (`2 -> 4`, `8 -> 16`, `12 -> 24`).

Report a correction for Q91

Question 92 MCQ · 7.0 marks

Source diagram or notation
6406533457390.Source diagram or notation
6406533457391.Source diagram or notation
6406533457392.Source diagram or notation
6406533457393.Source diagram or notation

Published solution

**Answer: D** **Topic:** Java Collections Framework — *Iterating Over a List<Double> Using an Enhanced For-Loop* ### Step-by-Step Solution **Step 1:** In `main()`, `List<Double> temp = expenseMap.get(name);` is a list of **`Double`** elements. **Step 2:** To iterate over each element `i` in `temp` using a for-each loop: - Options A and C declare the loop variable `i` as `List` or `List<Double>`, which fails to compile because the elements of `temp` are `Double`, not `List`. - Option B declares `int i : temp`, which fails to compile because a `Double` cannot auto-unbox to `int`. - **Option D** (`for (Double i : temp) { sum = sum + i; count = count + 1; }` — note the semicolon in code) correctly declares `Double i : temp`. **Step 3:** Therefore, **D** is correct. **Key Takeaway / Tip:** The element type of `List<Double> temp` is `Double` (or `double` via auto-unboxing), never `int` or `List<Double>`. A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Iterating Over a List<Double> Using an Enhanced For-Loop (correct choice: D). B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Iterating Over a List<Double> Using an Enhanced For-Loop (correct choice: D). C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Iterating Over a List<Double> Using an Enhanced For-Loop (correct choice: D). D: **Correct:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Iterating Over a List<Double> Using an Enhanced For-Loop. The element type of `List<Double> temp` is `Double` (or `double` via auto-unboxing), never `int` or `List<Double>`.

Report a correction for Q92

Question 93 MCQ · 7.0 marks

Source diagram or notation
6406533457394.Source diagram or notation
6406533457395.Source diagram or notation
6406533457396.Source diagram or notation
6406533457397.Source diagram or notation

Published solution

**Answer: C** **Topic:** Java Collections Framework — *Iteration Order of HashSet vs. TreeSet* ### Step-by-Step Solution **Step 1:** Compare the iteration guarantees of `HashSet` (`set1`) and `TreeSet` (`set2`): - **`HashSet<String>` (`set1`, iterated by `it1`)**: Uses a hash table and makes **no guarantee** about the iteration order of its elements (it visits elements in **unspecified order**, NOT insertion order or sorted order). - **`TreeSet<String>` (`set2`, iterated by `it2`)**: Uses a Red-Black tree and visits elements in ascending **sorted (natural) order**. **Step 2:** Therefore, **`it1` will visit elements of `set1` in unspecified order, and `it2` will visit elements of `set2` in sorted order** (**C**). **Key Takeaway / Tip:** `HashSet` has unspecified iteration order, `LinkedHashSet` preserves insertion order, and `TreeSet` maintains sorted order. A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Iteration Order of HashSet vs. TreeSet (correct choice: C). B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Iteration Order of HashSet vs. TreeSet (correct choice: C). C: **Correct:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Iteration Order of HashSet vs. TreeSet. `HashSet` has unspecified iteration order, `LinkedHashSet` preserves insertion order, and `TreeSet` maintains sorted order. D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Iteration Order of HashSet vs. TreeSet (correct choice: C).

Report a correction for Q93

Question 94 MCQ · 7.0 marks

Source diagram or notation
6406533457402.Source diagram or notation
6406533457403.Source diagram or notation
6406533457404.Source diagram or notation
6406533457405.Source diagram or notation

Published solution

**Answer: C** **Topic:** Object-Oriented Programming in Java — *Deep Cloning with Cloneable and super.clone()* ### Step-by-Step Solution **Step 1:** Inspect `Project.clone()`: ```java Project p = (Project) super.clone(); p.task1 = p.task1.clone(); p.task2 = p.task2.clone(); ``` Because `Project.clone()` explicitly clones `task1` and `task2` as well, it performs a **deep copy**! **Step 2:** Consequently, when `main()` executes: - `proj2.task1.taskName = "Research";` modifies **only** `proj2.task1` (`proj1.task1.taskName` remains `"Design"`). - `proj2.projectName = "ProjectY";` modifies **only** `proj2.projectName` (`proj1.projectName` remains `"ProjectX"`). **Step 3:** Thus, the output is: `ProjectX : Design` `ProjectY : Research` which matches **C**. **Key Takeaway / Tip:** Because `p.task1 = p.task1.clone();` creates a separate cloned `Task` object for `proj2`, modifying `proj2.task1.taskName` does not affect `proj1.task1.taskName`. A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Deep Cloning with Cloneable and super.clone() (correct choice: C). B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Deep Cloning with Cloneable and super.clone() (correct choice: C). C: **Correct:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Deep Cloning with Cloneable and super.clone(). Because `p.task1 = p.task1.clone();` creates a separate cloned `Task` object for `proj2`, modifying `proj2.task1.taskName` does not affect `proj1.task1.taskName`. D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Deep Cloning with Cloneable and super.clone() (correct choice: C).

Report a correction for Q94

Question 95 MSQ · 7.0 marks

Source diagram or notation
6406533457386.Source diagram or notation
6406533457387.Source diagram or notation
6406533457388.Source diagram or notation
6406533457389.Source diagram or notation
      **Appdev2** **Section Id :** 64065373861 **Section Number :** 7 **Section type :** Online **Mandatory or Optional :** Mandatory **Number of Questions :** 17 **Number of Questions to be attempted :** 17 **Section Marks :** 50 **Display Number Panel :** Yes **Section Negative Marks :** 0 **Group All Questions :** No **Enable Mark as Answered Mark for Review and** No **Clear Response :** **Section Maximum Duration :** 0 **Section Minimum Duration :** 0 **Section Time In :** Minutes **Maximum Instruction Time :** 0

Published solution

**Answer: B, C** **Topic:** Java Streams — *Filtering Stream Elements with Single or Chained Predicates* ### Step-by-Step Solution **Step 1:** To print the names of vehicles whose `mileage` is between `15.0` and `25.0` (inclusive), we must filter the `Stream<Vehicle>` before calling `.forEach(v -> System.out.println(v.name))`: - **A and D fail**: Calling `.map(v -> v.mileage >= 15.0 ...)` converts the `Stream<Vehicle>` into a `Stream<Boolean>`, so `v.name` in `forEach` causes a compilation error! - **B succeeds**: `.filter(v -> v.mileage >= 15.0 && v.mileage <= 25.0)` keeps matching `Vehicle` objects in a single predicate. - **C succeeds**: Chaining `.filter(v -> v.mileage >= 15.0).filter(v -> v.mileage <= 25.0)` applies both predicates sequentially and is completely equivalent to `&&`. **Step 2:** Therefore, **B and C** are correct. **Key Takeaway / Tip:** Use `.filter(predicate)` to select stream elements while preserving their type (`Stream<Vehicle>`); chaining two `.filter()` calls is equivalent to combining their predicates with `&&`. A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.
) does not satisfy the conditions derived in the step-by-step analysis for Filtering Stream Elements with Single or Chained Predicates (correct choice: B, C). B: **Correct:** Option B (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Filtering Stream Elements with Single or Chained Predicates. Use `.filter(predicate)` to select stream elements while preserving their type (`Stream<Vehicle>`); chaining two `.filter()` calls is equivalent to combining their predicates with `&&`. C: **Correct:** Option C (
Source diagram or notation unavailable. Please report this question for correction.
) matches our derived result under Filtering Stream Elements with Single or Chained Predicates. Use `.filter(predicate)` to select stream elements while preserving their type (`Stream<Vehicle>`); chaining two `.filter()` calls is equivalent to combining their predicates with `&&`. D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.
      **Appdev2** **Section Id :** 64065373861 **Section Number :** 7 **Section type :** Online **Mandatory or Optional :** Mandatory **Numb...) does not satisfy the conditions derived in the step-by-step analysis for Filtering Stream Elements with Single or Chained Predicates (correct choice: B, C).

Report a correction for Q95