Practice
Solution
Step 1: Understand Proxy's role
Proxy controls access and may delay creation of the real service (lazy initialization).Step 2: Trace the call flow
Client calls Proxy -> Proxy checks access -> Proxy creates real service if not already created -> Proxy forwards call -> Real service executes.Step 3: Eliminate incorrect options
B is incorrect because Proxy usually adds control logic before forwarding. C is incorrect as Proxy typically does not modify parameters (that's Decorator or Adapter). D describes Facade, not Proxy.Final Answer:
Option A -> Option A
- Assuming Proxy always forwards calls immediately without checks
- Confusing Proxy with Facade's simplification role
- Thinking Proxy modifies request parameters
Solution
Step 1: Understand DI and IoC flow
In Dependency Injection via IoC, the client requests a service from the container, which manages creation and injection.Step 2: Analyze options
Client requests the service from the IoC container, which then creates and injects dependencies into the client. correctly describes the client requesting the service and the container creating and injecting dependencies. Client creates the service instance directly, then passes it to the IoC container. reverses roles incorrectly. IoC container instantiates the service and injects it into the client before the client uses it. suggests container injects before client requests, which is inaccurate. Service creates the client instance and injects itself into the client. incorrectly states the service creates the client.Final Answer:
Option B -> Option BQuick Check:
IoC container controls creation; client depends on container to provide dependencies.
- Thinking client creates service instances directly
- Assuming container injects dependencies before client requests
- Confusing who controls object creation
Solution
Step 1: Understand method overloading
Method overloading occurs within the same class and involves multiple methods with the same name but different parameter lists, resolved at compile time.Step 2: Contrast with overriding
Method overriding involves a subclass redefining a method from its superclass, resolved at runtime via dynamic dispatch.Step 3: Analyze options
When you want to provide multiple behaviors for the same method name based on different parameter types or counts within the same class correctly describes overloading's use case. Options A, B, and C describe overriding or runtime polymorphism concepts.Final Answer:
Option B -> Option BQuick Check:
Overloading is about compile-time resolution based on parameters, not runtime behavior changes.
- Confusing overloading with overriding
- Thinking overloading involves runtime polymorphism
- Believing vtable is used for overloading
Solution
Step 1: Understand the problem requirement
The goal is to create a new object where nested mutable fields are independent, so changes in the copy do not affect the original.Step 2: Evaluate approaches
Manual shallow copy (A) shares nested references, causing side effects. Greedy selective copying (B) is not a standard approach and risks missing nested objects. JSON serialization (D) can lose methods and fail on special objects. Recursive deep copy (C) ensures all nested objects are duplicated, preserving independence.Final Answer:
Option D -> Option DQuick Check:
Deep copy duplicates nested objects -> no shared references [OK]
- Assuming shallow copy suffices for nested mutable fields
Solution
Step 1: Understand iterator stack usage
The iterator stack holds nodes along the current traversal path, not all nodes simultaneously.Step 2: Relate stack size to tree height
Maximum stack size corresponds to the height h of the tree, as children are pushed and popped during traversal.Final Answer:
Option D -> Option DQuick Check:
Stack size bounded by tree height h, not total nodes n [OK]
- Assuming stack holds all nodes at once
- Confusing height with log n for unbalanced trees
