Loading...
Loading...
Browse 4 real-world technical and behavioral interview questions about Inheritance. Review scenarios, edge cases, and architectural best practices.
Substitutability is a claim about behaviour, and signatures carry none of it. A subclass that rejects an argument its supertype accepted has strengthened a precondition, which the compiler cannot see: the code type-checks, and it breaks callers that were written correctly against the base type.
Encapsulation earns its place when a class owns an invariant that callers would otherwise each have to enforce, and polymorphism when a conditional grows with every new requirement. Composition versus inheritance is decided on evidence: how many axes vary, and whether every inherited operation is honest.
Encapsulation, inheritance, polymorphism and abstraction are worth stating as consequences rather than definitions - what each one buys you and what it costs. Abstraction decides what a type means to its caller; encapsulation protects how that meaning is upheld.
Use the strategy pattern instead of inheritance when behaviour varies independently from object identity. Composition avoids subclass explosion, enables runtime swapping and makes algorithms easier to test.