Bird
0
0

Why might a developer choose an abstract class over an interface in Java when designing a base type?

hard📝 Conceptual Q10 of 15
Java - Abstraction
Why might a developer choose an abstract class over an interface in Java when designing a base type?
ABecause abstract classes can be instantiated directly.
BBecause interfaces cannot have any methods.
CTo provide some shared method implementations and state (fields) along with abstract methods.
DTo avoid the need for subclasses to implement any methods.
Step-by-Step Solution
Solution:
  1. Step 1: Understand abstract class capabilities

    Abstract classes can have both concrete methods and fields to share code and state.
  2. Step 2: Compare with interfaces

    Interfaces cannot hold state and until recent versions had only abstract methods; they cannot provide shared fields.
  3. Final Answer:

    To provide some shared method implementations and state (fields) along with abstract methods. -> Option C
  4. Quick Check:

    Abstract class for shared code and state = B [OK]
Quick Trick: Abstract classes can hold fields and method code [OK]
Common Mistakes:
  • Thinking abstract classes can be instantiated
  • Believing interfaces have no methods at all
  • Assuming abstract classes remove implementation requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes