Q1. Explain the difference between an abstract class and an interface in Java (or C#, Python, etc.). When would you use each?
Why you'll be asked this: Assesses fundamental object-oriented programming (OOP) knowledge and understanding of design patterns. It also checks language-specific nuances.
Define each concept (abstract class: can have concrete methods, constructors, state; interface: defines a contract, no implementation before Java 8/9). Discuss key differences (multiple inheritance, access modifiers). Provide clear use cases for each (abstract class for 'is-a' relationships with common base functionality, interface for 'can-do' contracts across unrelated classes).
- Confusing the two concepts or providing incorrect definitions.
- Inability to articulate practical use cases beyond theoretical definitions.
- Lack of language-specific context if applicable.
- How have recent language updates (e.g., default methods in Java interfaces) impacted their usage?
- Can you give an example from a past project where you chose one over the other and why?
- Discuss the concept of 'composition over inheritance' in this context.