MauryaHub PYQ Practice

Programming Concepts using Java · Quiz 1 · Sep 2025

Programming Concepts using Java · Quiz 1 · Sep 2025

← 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.

15 / 15 published solutions

Question 95 MCQ · 7.0 marks

Source diagram or notation
6406535115614.
alpha ()
6406535115615.
beta ()
6406535115616.
gamma ()
6406535115617.
main ()

Published solution

**1. Expand the chain:** main calls alpha(3), which calls beta(2), then gamma(1), then gamma(0). The positive-argument test stops further calls at zero. **2. Locate the top frame:** At maximum depth the newest active invocation is gamma(0), so gamma() is on top of the stack. **Answer: C — gamma ().** A: **Incorrect:** alpha(3) is suspended while the deeper calls run. B: **Incorrect:** beta(2) is suspended below the gamma frames. C: **Correct:** gamma(0) is the most recently entered invocation at maximum depth. D: **Incorrect:** main is the bottom program frame, not the top.

Report a correction for Q95

Question 96 MCQ · 7.0 marks

Source diagram or notation
6406535115618.
21
6406535115619.
28
6406535115620.
25
6406535115621.
16

Published solution

**1. Follow mutation and aliasing:** square(arr) updates the original array [2,3,4] to [4,9,16] and returns its reference. arr and b therefore point to the same modified array. **2. Evaluate the sum:** arr[1]=9 and b[2]=16, so the printed value is 25. **Answer: C — 25.** A: **Incorrect:** This would incorrectly use the original 3 or another unchanged value. B: **Incorrect:** The required elements are 9 and 16, not values summing to 28. C: **Correct:** 9+16=25. D: **Incorrect:** Sixteen is only b[2], not the sum.

Report a correction for Q96

Question 97 MCQ · 7.0 marks

Source diagram or notation
6406535115622.Source diagram or notation
6406535115623.Source diagram or notation
6406535115624.Source diagram or notation
6406535115625.Source diagram or notation

Published solution

**1. Check the declared argument type:** equals(Object obj) receives Object. After testing instanceof Book, B explicitly casts to Book, allowing access to title and isbn. **2. Compare values:** String.equals compares text, so the target matches the “Clean Code”, “222” entry. found becomes true and the loop prints “Book Found”. **Answer: B — instanceof, explicit Book cast, and String.equals for both fields.** **Convention note:** The constructor comment stands for the field-initializing constructor specified in the question. The compared strings are non-null in this example; a general equals implementation should also handle nullable fields consistently and pair equals with hashCode. A: **Incorrect:** obj retains declared type Object, so obj.title and obj.isbn are not valid field accesses. B: **Correct:** The checked cast and two content comparisons implement the stated equality rule. C: **Incorrect:** Reference identity is false for the separately constructed target and library objects. D: **Incorrect:** Assigning Object obj directly to Book b needs an explicit narrowing cast.

Report a correction for Q97

Question 98 MCQ · 7.0 marks

Source diagram or notation
6406535115626.Source diagram or notation
6406535115627.Source diagram or notation
6406535115628.Source diagram or notation
6406535115629.Source diagram or notation

Published solution

**1. Initialize the superclass:** Person has only Person(String), so Student must explicitly invoke super(nm) to initialize its private name. **2. Initialize and print the subclass:** Assign rollNo=r. Student.toString() calls Person.toString() and appends the roll number, yielding “Aman : 101”. **Answer: D — public Student(String nm,int r){ super(nm); this.rollNo=r; }.** **Convention note:** The paper uses the traditional Java constructor rule, as in Java 17: an explicit super(...) or this(...) invocation is first. Later Java releases relax some constructor-prologue rules; the solution follows the exam’s language level. A: **Incorrect:** It implicitly requires a nonexistent Person() constructor. B: **Incorrect:** Under the Java 17-style rules used here, super(nm) must precede the field assignment. C: **Incorrect:** This does not provide the called (String,int) constructor and also directly accesses private Person.name. D: **Correct:** It calls the available superclass constructor before initializing rollNo.

Report a correction for Q98

Question 99 MCQ · 7.0 marks

Source diagram or notation
6406535115630.Source diagram or notation
6406535115631.Source diagram or notation
6406535115632.Source diagram or notation
6406535115633.Source diagram or notation

Published solution

**1. Trace the zero-argument call:** The actual object is Cylinder, so obj.area() enters Cylinder.area(). Its super.area() invokes Circle.area(), which first invokes Shape.area(). This prints “Generic Shape”, “Circle area”, then “Cylinder area”. **2. Resolve the overload:** obj.area(5.0) selects Circle.area(double), inherited by Cylinder. The two-argument Cylinder overload is not applicable, so the last line is “Circle area with radius: 5.0”. **Answer: A — Generic Shape; Circle area; Cylinder area; Circle area with radius: 5.0.** A: **Correct:** All four lines follow the explicit super calls and the one-argument overload. B: **Incorrect:** Cylinder is a Circle subtype, so the assignment is valid. C: **Incorrect:** The actual object invokes Cylinder.area(), adding the Cylinder line. D: **Incorrect:** Circle.area() prints its own line after calling Shape.area(); that line cannot be skipped.

Report a correction for Q99

Question 100 MCQ · 7.0 marks

Source diagram or notation
6406535115634.Source diagram or notation
6406535115635.Source diagram or notation
6406535115636.Source diagram or notation
6406535115637.Source diagram or notation

Published solution

**1. Identify the shallow copy:** l2 is a distinct Library object, but the copy constructor assigns books=l.books, sharing the array. The name fields are separate reference slots. **2. Apply the updates:** l2.name becomes TownLibrary without changing l1.name. Updating l2.books[1] changes the shared element to JavaScript. Output: “CityLibrary,JavaScript” followed by “TownLibrary,JavaScript”. **Answer: B — CityLibrary,JavaScript; TownLibrary,JavaScript.** A: **Incorrect:** The objects do not share their name field slots, so l1 stays CityLibrary. B: **Correct:** The names are independent while both read the same changed array element. C: **Incorrect:** The books array is shared, so l1 also reads JavaScript. D: **Incorrect:** l2.name changes to TownLibrary, and l1 also sees the array mutation.

Report a correction for Q100

Question 101 MCQ · 7.0 marks

Source diagram or notation
6406535115642.Source diagram or notation
6406535115643.Source diagram or notation
6406535115644.Source diagram or notation
6406535115645.Source diagram or notation

Published solution

**1. Identify real errors:** LINE 1 attempts to override final calculateBonus(); LINE 2 accesses private bonusRate from the subclass; LINE 3 assigns a general Employee object to a Manager reference. These are compilation errors. **2. Select the false assertion:** LINE 4 is a valid widening assignment from Manager to Employee. The statement claiming that this assignment is invalid is false. **Answer: D — the claim that LINE 4 is invalid is false.** A: **Incorrect:** True statement, not selected: the superclass method is final. B: **Incorrect:** True statement, not selected: private bonusRate is inaccessible in Manager; being static does not make it public. C: **Incorrect:** True statement, not selected: an Employee object need not be a Manager. D: **Correct:** False statement, selected: a superclass reference can hold a subclass object.

Report a correction for Q101

Question 102 MCQ · 7.0 marks

Source diagram or notation
6406535115646.Source diagram or notation
6406535115647.Source diagram or notation
6406535115648.Source diagram or notation
6406535115649.Source diagram or notation

Published solution

**1. Identify ownership:** printArea is a static interface method declared in Shape. Such methods are called through the declaring interface and are not inherited as methods of implementing classes. **2. Supply the argument:** c.area() gives \(\pi\cdot2^2=4\pi\), represented as 12.566370614359172. Shape.printArea(c.area()) prints the required line. **Answer: C — Shape.printArea(c.area());.** A: **Incorrect:** No unqualified printArea method is in scope in TestShape. B: **Incorrect:** A static interface method cannot be called through an implementing-class instance. C: **Correct:** Qualifying the call with Shape correctly names the declaring interface. D: **Incorrect:** Circle does not inherit the static interface method.

Report a correction for Q102

Question 103 MCQ · 6.0 marks

Source diagram or notation
6406535115638.Source diagram or notation
6406535115639.Source diagram or notation
6406535115640.Source diagram or notation
6406535115641.Source diagram or notation

Published solution

**1. Store a valid callback:** DeliveryApp implements Notifiable, so new DeliveryService(this) stores a valid reference to the calling app. Construction itself prints nothing. **2. Follow execution:** placeOrder() prints “Order placed”, processOrder() prints “Processing order”, and client.notifyUser() invokes DeliveryApp.notifyUser(), printing “Order delivered”. **Answer: D — Order placed; Processing order; Order delivered.** A: **Incorrect:** An implementing object can be passed to an interface-typed constructor parameter. B: **Incorrect:** The callback is initialized from this, and “Order placed” is printed first. C: **Incorrect:** Calling a declared interface method is legal and dynamically dispatches to its implementation. D: **Correct:** The app message, service message and callback message occur in that order.

Report a correction for Q103

Question 104 MCQ · 6.0 marks

Source diagram or notation
6406535115654.Source diagram or notation
6406535115655.Source diagram or notation
6406535115656.Source diagram or notation
6406535115657.Source diagram or notation

Published solution

**1. Resolve the inherited signature:** MusicPlayer, although declared abstract, provides a concrete public start() method. That concrete superclass method takes precedence over Camera’s default method of the same signature. **2. Execute the call:** SmartPhone inherits MusicPlayer.start(), so sp.start() prints “Music started”. No additional override is required. **Answer: B — Music started.** A: **Incorrect:** The interface default loses to the concrete superclass implementation. B: **Correct:** The inherited MusicPlayer method is selected. C: **Incorrect:** A concrete superclass implementation resolves this case; there is no unresolved default-method conflict. D: **Incorrect:** start() is an accessible inherited instance method.

Report a correction for Q104

Question 105 MCQ · 6.0 marks

Source diagram or notation
6406535115662.Source diagram or notation
6406535115663.Source diagram or notation
6406535115664.Source diagram or notation
6406535115665.Source diagram or notation

Published solution

**1. Check member lookup:** p has declared type Payment, which declares process() but not showUpiId(). Its actual UpiPayment object does not add members to the declared reference type. **2. Stop at compilation:** p.showUpiId() at LINE 1 therefore fails to compile. Although p.process() would dispatch to UpiPayment if the invalid line were repaired, no normal output is produced by the program as written. **Answer: A — Compilation error at LINE 1.** A: **Correct:** Payment does not expose the subclass-only showUpiId() method. B: **Incorrect:** The program does not compile successfully. C: **Incorrect:** This requires a valid cast or subclass-typed reference for the second call. D: **Incorrect:** There is a compilation error; additionally process() would dispatch to UpiPayment rather than Payment.

Report a correction for Q105

Question 106 MCQ · 8.0 marks

Source diagram or notation
6406535115650.Source diagram or notation
6406535115651.Source diagram or notation
6406535115652.Source diagram or notation
6406535115653.Source diagram or notation

Published solution

**1. Check compatibility:** SmartPhone implements SmartDevice, which extends Device. Both interface reference assignments are valid. SmartPhone overrides both start() and info(). **2. Dispatch all four calls:** Both objects execute the class bodies, irrespective of whether the reference type is Device or SmartDevice. Each pair prints “Phone starting...” followed by “SmartPhone with 5G”. **Answer: A — Phone starting...; SmartPhone with 5G; Phone starting...; SmartPhone with 5G.** A: **Correct:** Both pairs use SmartPhone’s concrete overrides. B: **Incorrect:** Declared interface types do not force default implementations when the class overrides them. C: **Incorrect:** A SmartPhone is also a Device through the interface inheritance chain. D: **Incorrect:** The class override is unambiguous and wins over both interface defaults.

Report a correction for Q106

Question 107 MCQ · 5.0 marks

Consider the Java code segment given below. class BookList { private class Book implements Printable { private String title; public Book(String t) { title = t; a public void print() { System.out.println("Book: " + title); } } private class BookIterator implements Iterable { private int idx; public BookIterator() { idx = -1; } public boolean has_next() { return idx < list.length - 1; } public Printable get_next() { idxt++; return list [idx] ; } : public Iterable getIterator() { return new BookIterator() ; + private Book[] list = { new Book("Java Basics"), new Book("Data Structures"), new Book("Design Patterns"), new Book("Algorithms") , new Book("Software Engineering") 3 Si public class TestBooks { public static void main(String[] args) { BookList myBooks = new BookList(); Iterable it = myBooks.getIterator(); while(it.has_next()) { it.get_next() .print(); iF From the following options, identify the appropriate definitions of Iterable and Printable.
6406535115659.Source diagram or notation
6406535115660.Source diagram or notation
6406535115661.Source diagram or notation

Published solution

**1. Match implements:** Book implements Printable and BookIterator implements Iterable, so both named abstractions must be interfaces rather than abstract classes. **2. Match the client expression:** it.has_next() requires boolean has_next(); it.get_next().print() requires get_next() to return a type exposing print(). The first exported option supplies Printable get_next() and void print(), satisfying both implementations and client calls. **Answer: A — First exported option — Iterable and Printable interfaces, with Printable get_next().** **Convention note:** The PDF resolves the OCR-corrupted braces and idx++ in the question. Its first option, consisting of two abstract classes, is absent from the export: the correct PDF option B is therefore the first exported option, with source key 6406535115659. The other two exported options correspond to PDF C and D. Only exported keys are used. Iterable here is a custom interface, not java.lang.Iterable. A: **Correct:** Both declarations are interfaces, and the Printable return type exposes print(). B: **Incorrect:** Printable is an abstract class, incompatible with Book implements Printable; returning Object also hides print() from the client. C: **Incorrect:** Ordinary interface instance methods cannot have these bodies without default or another appropriate method modifier.

Report a correction for Q107

Question 108 MSQ · 6.0 marks

Which of the following statements correctly describe **static typing** and **dynamic typing**?
6406535115666.
In dynamic typing, the type of a variable is determined at runtime and may change with the value assigned.
6406535115667.
Dynamic typing requires explicit declaration of variable names and their types before use.
6406535115668.
Static typing allows the compiler to catch type errors early and perform type- based optimizations.
6406535115669.
In static typing, variables can freely change their type at runtime by assigning values of different types.

Published solution

**1. Distinguish when compatibility is checked:** Static typing gives expressions and variables compile-time types and permits many invalid operations to be rejected before execution. Dynamic typing checks operations using the types of values at runtime. **2. Interpret reassignment:** In a typical dynamically typed language a variable name may successively bind to values of different types. A statically typed variable keeps its declared or inferred static type, although it can hold different compatible subtype objects. **Answer: A, C — In dynamic typing, the type of a variable is determined at runtime and may ; Static typing allows the compiler to catch type errors early and perform type-.** **Convention note:** More precisely, runtime values have types in dynamically typed languages; saying a variable “changes type” is common shorthand for rebinding. Static typing can use type inference and does not always require explicit annotations. A: **Correct:** This is the usual introductory description: the name can be rebound to differently typed runtime values. B: **Incorrect:** Explicit type declarations are not a requirement of dynamic typing. C: **Correct:** Compile-time type information supports early error checking and optimizations. D: **Incorrect:** Assignments must remain compatible with the variable’s fixed static type.

Report a correction for Q108

Question 109 MSQ · 7.0 marks

Source diagram or notation
6406535115670.Source diagram or notation
6406535115671.Source diagram or notation
6406535115672.Source diagram or notation
6406535115673.Source diagram or notation
      **MLF** **Section Id :** 640653106045 **Section Number :** 7 **Section type :** Online **Mandatory or Optional :** Mandatory **Number of Questions :** 12 **Number of Questions to be attempted :** 12 **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. Respect encapsulation:** Person holds an Address object in addr. Its city and country fields are private to Address, so Person cannot read them directly. Address already provides public toString(). **2. Build the text:** Concatenating addr with a String invokes its string representation automatically; explicitly using addr.toString() does the same here. B and D both produce “Person: Riya, Address: Bangalore, India”. **Answer: B, D — B and D — concatenate addr or addr.toString().** A: **Incorrect:** city and country are not fields or locals of Person. B: **Correct:** String concatenation uses Address.toString() for the non-null addr object. C: **Incorrect:** Address.city and Address.country are private and inaccessible from the separate Person class. D: **Correct:** The explicit public toString() call supplies the same address text.

Report a correction for Q109