MauryaHub PYQ Practice

Programming Concepts using Java · Quiz 2 · May 2025

Programming Concepts using Java · Quiz 2 · May 2025

← Course papers · Start practice / exam

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

13 / 16 published solutions

Question 202 MCQ · 1.0 marks

What percentage of total revenue do the SKUs LAP004 and LAP005 contribute together?
6406534435447.
10%
6406534435448.
20%
6406534435449.
15%
6406534435450.
25%       **Java** **Section Id :** 64065394386 **Section Number :** 13 **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

A published solution is not available for this question yet.

Report a correction for Q202

Question 204 MCQ · 6.0 marks

Source diagram or notation
6406534435453.Source diagram or notation
6406534435454.Source diagram or notation
6406534435455.Source diagram or notation
6406534435456.Source diagram or notation

Published solution

**1. Erase each method’s parameter type:** Both <T extends Number> printDetails(T) and <U extends Number> printDetails(U) erase to printDetails(Number). Changing the type-parameter name or the method body does not create a distinct overload. **2. Identify the collision:** LINE 2 redeclares the same erased signature already introduced at LINE 1, so the class fails compilation. This is one duplicate-signature conflict between those two declarations. **3. Check the unbounded overload:** LINE 3 has an unbounded T, which erases to Object. printDetails(Object) is a different signature and can coexist with one printDetails(Number) method. No output is produced by the class as written because compilation fails. **Answer: C — LINE 2 duplicates LINE 1’s erased signature.** **Convention note:** A compiler reports a duplicate declaration at the later declaration; the underlying conflict is between LINE 1 and LINE 2, rather than LINE 2 being intrinsically invalid on its own. A: **Incorrect:** LINE 3 erases to Object and does not conflict with the Number overload. B: **Incorrect:** LINE 1 and LINE 3 have distinct erased parameter types. C: **Correct:** LINE 2 duplicates LINE 1’s erased Number signature; LINE 3 is a valid distinct overload. D: **Incorrect:** The duplicate Number method prevents compilation, so no three-line runtime output occurs.

Report a correction for Q204

Question 205 MCQ · 6.0 marks

Source diagram or notation
6406534435461.Source diagram or notation
6406534435462.Source diagram or notation
6406534435463.Source diagram or notation
6406534435464.Source diagram or notation

Published solution

**1. Build the first set:** The list contains 20,30,10,40. Constructing HashSet<Integer> retains those four distinct values, without promising iteration order. **2. Build the sorted set:** TreeSet<Integer>(set1) copies the values into their natural numeric order, giving 10,20,30,40. **3. Add the same elements again:** set2.addAll(set1) introduces no new values because sets reject duplicates. Printing the TreeSet therefore gives [10, 20, 30, 40]. **Answer: B — [10, 20, 30, 40].** A: **Incorrect:** A set cannot contain a second copy of each element. B: **Correct:** TreeSet prints each distinct value once in sorted order. C: **Incorrect:** The unspecified-order description applies to HashSet, but the printed object is a TreeSet. D: **Incorrect:** Both constructors populate their sets; the result is not empty.

Report a correction for Q205

Question 206 MCQ · 6.0 marks

Source diagram or notation
6406534435473.Source diagram or notation
6406534435474.Source diagram or notation
6406534435475.Source diagram or notation
6406534435476.Source diagram or notation

Published solution

**1. Enable assertions as specified:** The java -ea command enables the assertions in the shown application classes. The constructor receives username "admin" and password "", an empty but non-null String. **2. Check the assertions in order:** assert-1 (u!=null) passes. assert-2 (p!=null) also passes. Inside login(), assert-3 (!username.isEmpty()) passes because "admin" is nonempty. **3. Locate the first failure:** assert-4 requires password.length()>=6. The supplied empty password has length zero, so this is the first false assertion and throws AssertionError. The outer print cannot complete because login() does not return normally. **Answer: D — assert-4.** A: **Incorrect:** The username is not null, so this passes. B: **Incorrect:** An empty string is not a null reference, so this passes. C: **Incorrect:** The username admin is nonempty, so this passes. D: **Correct:** The password length is 0, which fails the minimum length 6.

Report a correction for Q206

Question 207 MCQ · 6.0 marks

Source diagram or notation
6406534435477.Source diagram or notation
6406534435478.Source diagram or notation
6406534435479.Source diagram or notation
6406534435480.Source diagram or notation

A published solution is not available for this question yet.

Report a correction for Q207

Question 208 MCQ · 6.0 marks

Source diagram or notation
6406534435485.
2 4 6 8
6406534435486.
4 6 8 10
6406534435487.
4 10 16 22
6406534435488.
8 16 24 32

Published solution

**1. Generate the arithmetic progression:** Stream.iterate(5,n→n+3) yields 5,8,11,14,17,20,23,26,29,32,… . **2. Find the first four multiples of four:** In \(n=5+3k\), divisibility by 4 requires \(1+3k\equiv0\pmod4\), so \(k\equiv1\pmod4\). The first retained values are 8,20,32,44. **3. Apply map and limit:** Integer division by 2 changes those to 4,10,16,22. limit(4) stops the otherwise infinite stream after those four outputs; forEach prints them in encounter order with spaces. **Answer: C — 4 10 16 22.** A: **Incorrect:** These are not the halves of the first four retained progression terms. B: **Incorrect:** This misses the progression’s spacing after filtering. C: **Correct:** 8,20,32,44 divided by 2 give 4,10,16,22. D: **Incorrect:** This does not apply the progression/filter/map combination correctly.

Report a correction for Q208

Question 209 MCQ · 6.0 marks

Source diagram or notation
6406534435489.
10 20 25 15 5 30 35
6406534435490.
10 20 25 15 5 30 35
6406534435491.
10 20 25 15 5 30
6406534435492.
10 20 25 15 5 30 35

Published solution

**1. Apply takeWhile to the ordered list:** The list is [10,20,25,15,5,30,35]. The initial even prefix is 10,20. takeWhile stops at the first odd value 25 and does not later include the even 30. **2. Apply dropWhile to a new stream of the same list:** It drops the initial even prefix 10,20, then keeps every remaining value, including both odd and even ones: 25,15,5,30,35. Neither stream mutates the original list. **3. Preserve the line break:** The explicit println between streams gives first line “10 20” and second line “25 15 5 30 35”, ignoring the trailing spaces after individual values. **Answer: B — first line: 10 20; second line: 25 15 5 30 35.** A: **Incorrect:** takeWhile excludes the first failing value 25; it is not part of the first line. B: **Correct:** The first line is the even prefix and the second line is the complete remaining suffix. C: **Incorrect:** 25 is incorrectly included in the first line and 35 is incorrectly omitted from the second. D: **Incorrect:** A newline is explicitly printed, and takeWhile does not print the whole list.

Report a correction for Q209

Question 210 MCQ · 6.0 marks

Source diagram or notation
6406534435493.Source diagram or notation
6406534435494.Source diagram or notation
6406534435495.Source diagram or notation
6406534435496.Source diagram or notation

Published solution

**1. Check the assignment:** A StreetDancer is a Dancer, so assigning new StreetDancer() to a Dancer reference is valid upcasting. **2. Resolve the no-argument call:** StreetDancer does not override perform(), so d.perform() uses the inherited Dancer.perform() and prints Dancer performs. **3. Resolve the String overload and dispatch:** d.perform("hip-hop") selects the String-parameter method. StreetDancer overrides that exact signature; the different parameter name move versus style is irrelevant. Dynamic dispatch therefore prints StreetDancer performs hip-hop. **Answer: D — Dancer performs; then StreetDancer performs hip-hop.** A: **Incorrect:** A superclass reference can refer to a subclass object. B: **Incorrect:** Overloading selects a signature and overriding selects its runtime implementation; no ambiguity occurs. C: **Incorrect:** The String method is overridden and dispatches to StreetDancer, not Dancer. D: **Correct:** The no-argument inherited method runs first, followed by the overridden String method.

Report a correction for Q210

Question 211 MCQ · 7.0 marks

Source diagram or notation
6406534435457.Source diagram or notation
6406534435458.Source diagram or notation
6406534435459.Source diagram or notation
6406534435460.Source diagram or notation

Published solution

**1. Initialize the combined map:** Copying dept1 gives HR=75, Finance=80 and Tech=95. Map.put is valid and does not create a duplicate-key compilation problem. **2. Merge each second-map value:** The remapping function is Math.max. Thus Finance becomes \(\max(80,85)=85\), Tech stays \(\max(95,90)=95\), and HR becomes \(\max(75,78)=78\). Admin is absent, so it is inserted as 70. **3. Print in sorted key order:** TreeMap orders the keys Admin,Finance,HR,Tech, producing {Admin=70, Finance=85, HR=78, Tech=95}. **Answer: B — {Admin=70, Finance=85, HR=78, Tech=95}.** A: **Incorrect:** Map.put and merge are valid; repeated keys do not cause compilation errors. B: **Correct:** This is the maximum for each shared key, in TreeMap key order. C: **Incorrect:** A map stores one value per key and cannot print duplicate Finance, HR and Tech mappings. D: **Incorrect:** These are sums, but the code uses Math.max.

Report a correction for Q211

Question 212 MCQ · 7.0 marks

Source diagram or notation
6406534435469.Source diagram or notation
6406534435470.Source diagram or notation
6406534435471.Source diagram or notation
6406534435472.Source diagram or notation

Published solution

**1. Evaluate the first authentication:** The first call uses guest and 12345, so it takes the unsuccessful branch and calls logger.logEvent(""). **2. Follow the checked exception:** The logger tests content==null || content.isEmpty(). The empty string satisfies isEmpty(), so LogFailureException("Log content is empty") is thrown before any LOG line is printed. **3. Transfer control out of the try:** authenticate propagates that checked exception to the catch block in main. The second admin authentication is inside the same try and is skipped. The only printed line is Exception: Log content is empty. **Answer: B — Exception: Log content is empty.** A: **Incorrect:** The admin call is skipped after the earlier guest call throws. B: **Correct:** The catch prints this exception message and no log line. C: **Incorrect:** The second call does not resume after the catch; it is skipped. D: **Incorrect:** The guest branch logs an empty message and throws instead of logging a success.

Report a correction for Q212

Question 213 MCQ · 7.0 marks

Source diagram or notation
6406534435481.
125.0
6406534435482.
75.0
6406534435483.
50.0
6406534435484.
Cloning not supported

Published solution

**1. Trace the clone:** Rectangle implements Cloneable, so Object.clone can copy the runtime Square object. The covariant clone methods return that new object through Rectangle and Square references without changing its runtime type. **2. Track copied primitive fields:** Initially both s1 and s2 have width=5 and height=5. Updating s1.width to 10 affects only s1. The code does not update its height merely because the class is named Square. **3. Compute both areas:** \(s1.getArea()=10\cdot5=50\), while \(s2.getArea()=5\cdot5=25\). Their double sum prints 75.0. **Answer: B — 75.0.** A: **Incorrect:** This would incorrectly treat s1 as a 10-by-10 square after changing only width. B: **Correct:** The areas are 50.0 and 25.0, which sum to 75.0. C: **Incorrect:** 50.0 is only s1’s area, omitting the clone’s area. D: **Incorrect:** Cloneable is implemented, so the shown clone is supported.

Report a correction for Q213

Question 214 MCQ · 8.0 marks

Source diagram or notation
6406534435465.Source diagram or notation
6406534435466.Source diagram or notation
6406534435467.Source diagram or notation
6406534435468.Source diagram or notation

A published solution is not available for this question yet.

Report a correction for Q214

Question 215 MSQ · 7.0 marks

Source diagram or notation
6406534435497.Source diagram or notation
6406534435498.Source diagram or notation
6406534435499.Source diagram or notation
6406534435500.Source diagram or notation

Published solution

**1. Read the classification rule:** isPopular(count) returns count>2. The book map has W=4,X=1,Y=3,Z=2; W and Y are popular, while X and Z are less-read. Equality at 2 is not popular. **2. Check equivalent predicates:** isPopular(entry.getValue()) applies the helper to the borrow count. entry.getValue()>2 performs the identical comparison directly. Either predicate produces the required partition. **3. Explain output order and rejected fields:** TreeSet sorts the book names, yielding [W,Y] and [X,Z]. Key length examines the title/name instead of the count; containsKey(entry.getValue()) searches a String-keyed map using an Integer value and does not test popularity. **Answer: A, B — isPopular(entry.getValue()) or entry.getValue()>2.** A: **Correct:** The helper compares the entry’s count against the required strict threshold. B: **Correct:** This directly implements the same count>2 condition. C: **Incorrect:** Every shown key has length 1, and key length is not the borrowing criterion. D: **Incorrect:** The map keys are book-name Strings, not the Integer counts being passed to containsKey.

Report a correction for Q215

Question 216 MSQ · 7.0 marks

Source diagram or notation
6406534435505.Source diagram or notation
6406534435506.Source diagram or notation
6406534435507.Source diagram or notation
6406534435508.Source diagram or notation

Published solution

**1. Determine the deque’s head:** Each push adds to the front, so after apple,banana,cherry,date are pushed, head-to-tail order is date,cherry,banana,apple. The sought head is not initially cherry. **2. Require progress through the loop:** pop() and remove() both return and remove the head of a nonempty ArrayDeque. They first remove date, then remove cherry, at which point the comparison succeeds and returns Element found. **3. Reject non-removing accessors:** peek() and element() inspect date without removing it. Since date is not the sought element, the while loop repeats forever with the same nonempty deque. **4. Check the actual String comparison:** The code uses ==, which compares references. In this exact program both occurrences of the literal "cherry" refer to the same interned String, so the reference comparison succeeds when cherry is removed. **Answer: C, D — pop() or remove().** **Convention note:** For arbitrary String inputs, use .equals(element) rather than == to compare contents. The literal interning in this exact example is why the supplied reference comparisons happen to work. A: **Incorrect:** peek does not remove date, so this loop does not advance to cherry. B: **Incorrect:** element also leaves the head unchanged and causes the same nontermination. C: **Correct:** pop removes date and then cherry, allowing the exact shown literal comparison to succeed. D: **Correct:** remove removes the deque head on each iteration, just as needed here.

Report a correction for Q216

Question 217 MSQ · 7.0 marks

Source diagram or notation
6406534435509.Source diagram or notation
6406534435510.Source diagram or notation
6406534435511.Source diagram or notation
6406534435512.Source diagram or notation

Published solution

**1. Establish the original output:** The four strings a,bb,ccc,dddd have lengths 1,2,3,4. The map operation computes those lengths and println prints each on its own line. **2. Compare alternative sources:** A List stream over the same strings and Arrays.stream over the same String array both preserve that order and compute the same lengths. The method reference String::length is equivalent to s→s.length(). **3. Compare the generated integer stream:** Stream.iterate(1,n→n+1).limit(4) directly generates 1,2,3,4 and therefore prints the same output even though it does not process strings. **4. Inspect the filtered alternative:** Filtering strings with length()>2 retains only ccc and dddd, so it prints only 3 and 4 and is not equivalent. **Answer: A, B, C — A, B and C; output 1,2,3,4 on separate lines.** A: **Correct:** The list supplies the same strings in the same order. B: **Correct:** The limited integer stream generates exactly the four printed length values. C: **Correct:** Array streaming and method references produce the same length sequence. D: **Incorrect:** The filter removes the first two strings, changing the output to only 3 and 4.

Report a correction for Q217

Question 218 MSQ · 8.0 marks

Source diagram or notation
6406534435501.Source diagram or notation
6406534435502.Source diagram or notation
6406534435503.Source diagram or notation
6406534435504.Source diagram or notation
      **Statistics1** **Section Id :** 64065394387 **Section Number :** 14 **Section type :** Online **Mandatory or Optional :** Mandatory **Number of Questions :** 14 **Number of Questions to be attempted :** 14 **Section Marks :** 40 **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

**1. Check both call sites:** The method is called with List<Manager> containing Rohan,Arjun and List<Developer> containing Karthik,Diya. It must accept both list types and expose Employee.getName for each element. **2. Use an upper-bounded wildcard or type parameter:** List<? extends Employee> permits either subtype list and reads elements as Employees. The generic header <T extends Employee> with List<T> also permits independent inference of Manager or Developer at each call. **3. Reject invariance and a narrow subtype:** List<Object> cannot accept List<Manager> or List<Developer>, since generic lists are invariant, and Object does not expose getName. List<Developer> supports only the developer call, not the manager call. Both valid headers print Rohan Arjun Karthik Diya. **Answer: A, B — List<? extends Employee> or <T extends Employee> with List<T>.** A: **Correct:** The wildcard accepts lists of any Employee subtype and allows getName on read values. B: **Correct:** The bounded type parameter is inferred separately as Manager and Developer at the two calls. C: **Incorrect:** Generic invariance rejects both arguments, and Object lacks getName. D: **Incorrect:** The manager list is not a List<Developer>, so this does not support the full program.

Report a correction for Q218