Java Fundamentals: Polymorphism and Monolith Versus Microservices
VisaSoftware Engineer · OnsiteLast updated
A Java fundamentals question pair: explain polymorphism, including overriding, dynamic dispatch and overload resolution, and compare monolithic and microservices architectures. It tests precise language mechanics, concrete examples, and balanced reasoning about deployment, scaling, consistency and operational trade-offs.
This round opened with Java fundamentals. Two of the questions were reported: explain polymorphism, and compare a monolithic architecture with microservices.
Clarifying Questions
- Should the polymorphism answer focus on Java's mechanics specifically, or on the object-oriented concept in general?
- For the architecture comparison, is there a particular system, team size or product stage in mind?
Part 1 — Polymorphism in Java
What is polymorphism? Explain the forms it takes in Java and how the JVM decides which method implementation runs, and give a short code example.
What This Part Should Cover
- Runtime polymorphism through overriding and dynamic dispatch, contrasted with compile-time overload resolution.
- What cannot be overridden (static, private and final methods, and fields), and why.
- A concrete example in which a superclass or interface reference points to subclass objects, and the design benefit that brings.
Part 2 — Monolith versus microservices
Compare a monolithic architecture with a microservices architecture. When would you choose each, and what does moving from one to the other cost?
What This Part Should Cover
- Deployment, scaling, fault isolation and technology independence.
- The costs of distribution: network failures, data consistency across services, observability and operational overhead.
- A reasoned recommendation for a given situation, and an incremental migration path.
Hints
Hint 1
Compile time versus run time: Consider which decisions the compiler makes from declared types, and which are deferred until the object's actual class is known.
Hint 2
Argue from the team and the domain: The choice depends less on technology than on team size, the need for independent deployment, and how cleanly the domain splits. Tie each advantage to the cost that comes with it.
Follow-up questions
- How does the JVM implement virtual method calls, and how does the JIT compiler make them cheap?
- Is an overloaded method chosen from the runtime types of its arguments? Show an example where the result surprises people.
- How would you keep data consistent when one operation spans two microservices that each own a database?
- What is a modular monolith, and when is it a better choice than either extreme?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.