Difficulty: Easy
Correct Answer: 1, 4
Explanation:
Introduction / Context:
Code reuse is a principal OO goal. In C#, the most common reuse mechanisms are inheritance (specialization and reuse of base behavior) and containership/composition (reusing existing types as parts of larger types).
Given Data / Assumptions:
Concept / Approach:
Inheritance allows derived classes to reuse and extend base behavior. Containership (composition/aggregation) lets a class reuse existing classes by holding them as fields and delegating work. While generics and polymorphism are powerful, the classic “reuse mechanisms” are inheritance and composition.
Step-by-Step Solution:
Verification / Alternative check:
Review design patterns: composition-over-inheritance is a maxim precisely because both are established reuse techniques.
Why Other Options Are Wrong:
They emphasize concepts that are important but either do not directly provide code reuse (encapsulation) or are language features/behaviors rather than reuse mechanisms (generics/polymorphism).
Common Pitfalls:
Equating “polymorphism” with reuse; conflating C++ templates with C# generics and their role.
Final Answer:
1, 4
Derived
object if each int
is 4 bytes (ignore header/alignment)?
Discussion & Comments