**1. Expand mutual recursion:** Starting from main, the active chain becomes methodA(3)→methodB(2)→methodC(1)→methodA(0).
**2. Stop at the base condition:** methodA(0) does not call another method. At this deepest instant it is the most recently entered invocation, so methodA() is at the top of the stack.
**Answer: A — methodA().**
A: **Correct:** The deepest invocation is methodA(0).
B: **Incorrect:** methodB(2) is suspended below methodC and the final methodA.
C: **Incorrect:** methodC(1) calls methodA(0), so it is not the top frame at maximum depth.
D: **Incorrect:** main is waiting below all these calls.
**1. Trace login():** The actual object is Admin. Its no-argument login() calls User.login(), which calls Account.login(); unwinding prints “Basic login”, “User login”, then “Admin login”.
**2. Trace login(String):** The String signature is available through User and overridden by Admin. Dynamic dispatch prints “Admin login with code: 9999”.
**Answer: A — Basic login; User login; Admin login; Admin login with code: 9999.**
A: **Correct:** This preserves all explicit super calls and dispatches the String overload to Admin.
B: **Incorrect:** An Admin object is compatible with a User reference.
C: **Incorrect:** Both calls dispatch to Admin’s applicable overrides; the Admin line cannot be omitted.
D: **Incorrect:** Admin.login() explicitly calls User.login(), so the User line also appears.
**1. Initialize Animal:** Animal has only its String constructor, so Dog must invoke super(n) to initialize the inherited private name. The remaining assignment initializes breed.
**2. Print the actual object:** Dog.toString() uses Animal.toString() and appends breed. The Animal-typed variable still dispatches to Dog’s override, yielding “Name: Rocky, Breed: Golden Retriever”.
**Answer: B — super(n);.**
A: **Incorrect:** this(n) would require a one-argument Dog constructor, which is absent.
B: **Correct:** super(n) invokes the available Animal constructor.
C: **Incorrect:** Animal(n) is not constructor-invocation syntax.
D: **Incorrect:** A superclass constructor is invoked as super(...), not super.Animal(...).
**1. Follow cases 0 and 1:** At i=0, print “Zero” and break. At i=1, print “One” and fall through because case 1 has no break; case 2 then prints “Two” and breaks.
**2. Follow case 2:** At i=2, enter case 2 directly and print only “Two”. A newline is printed after each switch, producing three lines: “Zero”, “One Two”, “Two”.
**Answer: A — Lines: Zero; One Two; Two.**
A: **Correct:** This matches the break and fall-through behavior.
B: **Incorrect:** Case 2 does not jump backwards to case 1; the final line contains only Two.
C: **Incorrect:** The matched case 2 breaks before default.
D: **Incorrect:** Both i=1 and i=2 match explicit cases, so default does not run.
**1. Use inherited accessible methods:** acc is declared SavingsAccount and refers to PremiumSavingsAccount. It exposes viewBalance() and calculateInterest(), but not the subclass-only offerPremiumBenefits().
**2. Downcast the actual subtype:** ((PremiumSavingsAccount)acc).offerPremiumBenefits() compiles and the runtime check succeeds. It adds “Offering premium benefits” after the two existing messages.
**Answer: C — ((PremiumSavingsAccount)acc).offerPremiumBenefits();.**
A: **Incorrect:** SavingsAccount does not declare the premium-only method.
B: **Incorrect:** super is unavailable in static main, and BankApp does not extend the account class.
C: **Correct:** The downcast exposes the subclass method and is valid for this actual object.
D: **Incorrect:** The method is an instance method, not a static class method.
**1. Inspect the element type:** printables is Object[], so the compile-time type of printables[i] is Object, which has no print(). Both stored objects implement Printable.
**2. Cast to the common interface:** ((Printable)printables[i]).print() works for both entries and dispatches to Book.print() and Magazine.print(), producing the requested two lines.
**Answer: B — ((Printable)printables[i]).print();.**
A: **Incorrect:** Object does not declare print(), so this fails to compile.
B: **Correct:** Both elements implement Printable, making each cast safe and exposing print().
C: **Incorrect:** The cast works for Book but fails with ClassCastException on the Magazine entry.
D: **Incorrect:** The first element is Book, so casting it to Magazine fails immediately.
**1. Inherit the default:** Circle does not override draw(), so it inherits Shape’s complete default body. It can therefore be concrete without declaring draw() itself.
**2. Dispatch each call:** s1.draw() prints “Drawing a shape”. Square overrides draw(), so s2.draw() prints “Drawing a square”.
**Answer: B — Drawing a shape; Drawing a square.**
A: **Incorrect:** The default method already supplies the required implementation.
B: **Correct:** The Circle default and Square override run in that order.
C: **Incorrect:** There are two calls, and Square’s call also prints its message.
D: **Incorrect:** Circle inherits a valid implementation, so its call does not fail.
**1. Recover the accessible abstraction:** nav.next() returns Object. The actual Book is private inside BookShelf, but it extends the accessible abstract class Displayable, which declares show().
**2. Cast and dispatch:** ((Displayable)nav.next()).show() accesses that method and dispatches to Book.show(). With the intended advancing iterator, the titles print as “Swami, Pyre, Palace,” with the spaces specified by the print statement.
**Answer: A — ((Displayable)nav.next()).show();.**
**Convention note:** The iterator constructor and traversal methods are shown as placeholders; assume their stated initialization, availability test and advancing behavior. The question tests the client-side cast.
A: **Correct:** Displayable is accessible and every returned Book is its subtype.
B: **Incorrect:** Book is private, and shelf has no next() method; next() belongs to nav.
C: **Incorrect:** BookShelf does not declare show(), and the returned objects are books rather than shelves.
D: **Incorrect:** Object does not declare show(), so the uncast call fails.
**1. Distinguish an alias from a copied object:** b2=b1 makes b2 refer to the same Book as b1. In contrast, new Book(b1) creates b3 with its own price field initialized to 500.
**2. Apply mutation:** b2.setPrice(600) changes the shared b1/b2 object, leaving b3 unchanged. The lines are “b1: Title: Java, Price: 600” and “b3: Title: Java, Price: 500”.
**Answer: C — b1: Title: Java, Price: 600; b3: Title: Java, Price: 500.**
**Convention note:** The export contains only three keyed options; PDF option D was merged into the tail of C’s extracted text. The solution uses C’s clearly displayed PDF output and preserves every exported option key without inventing a fourth key.
A: **Incorrect:** The alias b2 changes b1, so b1 cannot remain at 500.
B: **Incorrect:** This reverses the effect: b1 changes while the separately copied b3 does not.
C: **Correct:** The PDF’s C correctly gives b1=600 and b3=500; the extra trailing OCR text belongs to the omitted fourth PDF option and is not part of C’s intended output.
**1. Detect the competing defaults:** Printer and Scanner independently define the same default print() signature. Neither interface is more specific, and no superclass method resolves the conflict.
**2. Require an override:** MultiFunctionDevice must supply its own print() implementation to resolve the two defaults. Its empty class declaration at LINE 1 is a compilation error, so no document message prints.
**Answer: C — Compilation error at LINE 1: conflicting default print() methods.**
A: **Incorrect:** The compiler cannot arbitrarily choose Printer’s default.
B: **Incorrect:** The compiler cannot arbitrarily choose Scanner’s default.
C: **Correct:** The unrelated default methods must be resolved by an overriding method.
D: **Incorrect:** The inheritance conflict already invalidates the class at LINE 1; this is not merely a call-site type-name issue.
**1. Hide implementation, expose a superclass:** Department.Manager is private, but it extends accessible Employee. The returned Manager object can be widened to an Employee reference without the client naming Manager.
**2. Invoke dynamically:** Employee managerObj=dept.getManager() exposes show(). Since the actual object is Manager, its override prints “Manager::show()”.
**Answer: A — Employee managerObj = dept.getManager();.**
A: **Correct:** The accessible superclass is assignment-compatible and exposes the overridden method.
B: **Incorrect:** The unqualified private inner class name is unavailable here.
C: **Incorrect:** Qualifying the name does not remove Manager’s private access restriction.
D: **Incorrect:** Manager is an Employee, not a Department, so this assignment is incompatible.
Which of the following statements correctly describe interface and specification in software
components?
6406534364797.
An interface includes function signatures, arguments, and return types.
6406534364798.
Specification refers to the intended input-output behavior of the component.
6406534364799.
Interface helps describe how a component is implemented internally.
6406534364800.
A good specification language should balance abstraction and detail.
Published solution
**1. Separate the contract layers:** An interface describes callable operations and their signatures; a specification describes the promised behavior, such as relationships between valid inputs and outputs. Neither requires exposing implementation internals.
**2. Judge specification quality:** Useful specifications hide irrelevant details while stating enough constraints to define correct behavior. This makes A, B and D true.
**Answer: A, B, D — An interface includes function signatures, arguments, and return types.; Specification refers to the intended input-output behavior of the component.; A good specification language should balance abstraction and detail..**
A: **Correct:** Signatures describe how clients supply arguments and receive results.
B: **Correct:** The specification states the intended observable behavior.
C: **Incorrect:** Implementation algorithms and internal representations are not the interface’s purpose.
D: **Correct:** Abstraction must be balanced with enough precision to constrain behavior.
Which among the following statements is/are **true** about activation records?
6406534364801.
Multiple activation records of the same function can exist on the stack during
recursion.
6406534364802.
Activation records created for functions are allocated in heap.
6406534364803.
The return value link in an activation record identifies the memory location for
storing the function’s return value.
6406534364804.
The lifetime of a variable extends beyond the removal of its activation record
from the stack.
Published solution
**1. Model per-call state:** Each recursive invocation needs its own activation record while earlier invocations remain active, so several frames for one function can coexist on the call stack.
**2. Interpret return information:** In the stated activation-record model, the return-value link identifies where the result is delivered. Frame-local storage does not retain its lifetime after the frame is removed; heap objects referenced from the frame are a separate matter.
**Answer: A, C — Multiple activation records of the same function can exist on the stack during ; The return value link in an activation record identifies the memory location for .**
**Convention note:** This is the course’s conceptual stack-frame model. An actual JVM may return values through operand stacks or optimized machine conventions rather than a literal field named “return value link”.
A: **Correct:** Each active recursive invocation has separate call-local state.
B: **Incorrect:** In the textbook model here, activation records belong to the call stack, not the object heap.
C: **Correct:** This link identifies the designated result destination in the conceptual model.
D: **Incorrect:** A frame-local variable’s lifetime ends with its activation; a surviving referenced object is not the same as the local variable.
public String toString(){
return title + " " + author;
}
public String toString(){
return title + " " + author.name;
6406534364808.
*
Published solution
**1. Override the correct signature:** Printing book uses public String toString() with no parameters. Author.toString() already returns “authored by R.K. Narayan”.
**2. Compose the representation:** A explicitly calls author.toString(); C concatenates author and gets its string representation automatically. Both return “Malgudi Days authored by R.K. Narayan”.
**Answer: A, C — A and C — no-argument toString() with explicit or implicit Author conversion.**
**Convention note:** The PDF restores the option boundaries: the author.name implementation is option D, although the export merges its text into C and gives D as an OCR artifact. Exact exported option keys are retained.
A: **Correct:** The no-argument override explicitly obtains the Author representation.
B: **Incorrect:** toString(Author) is an overload, so println(book) does not use it.
C: **Correct:** Concatenating the non-null Author object invokes its string representation.
D: **Incorrect:** Author.name is private to the separate Author class and cannot be accessed directly by Book.
**Appdev2**
**Section Id :** 64065392559
**Section Number :** 8
**Section type :** Online
**Mandatory or Optional :** Mandatory
**Number of Questions :** 15
**Number of Questions to be attempted :** 15
**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
**1. Check overriding and visibility:** calculateIncome() is final in Doctor, so SpecialistDoctor cannot redeclare it with the same signature. The two fields are protected, however, so the subclass may access them directly.
**2. Check reference assignments:** Doctor d1=new SpecialistDoctor(10) is valid widening. SpecialistDoctor sd1=new Doctor(12) is invalid because an ordinary Doctor object is not a SpecialistDoctor. Thus LINE 1 and LINE 4 are the real errors.
**Answer: A, D — A and D — errors at LINE 1 and LINE 4.**
A: **Correct:** The attempted override violates the final superclass declaration.
B: **Incorrect:** Both fields are protected and accessible from this subclass; being static does not prevent access.
C: **Incorrect:** A Doctor reference can hold a SpecialistDoctor object.
D: **Correct:** A SpecialistDoctor reference cannot hold a newly created ordinary Doctor object.