Bird
Raised Fist0

A candidate claims that interfaces can contain instance variables to hold state, just like abstract classes. What is the flaw in this statement?

medium🐞 Bug Identification Q7 of Q15
OOP & Design Patterns - Abstraction - Abstract Class vs Interface - When to Use Which
A candidate claims that interfaces can contain instance variables to hold state, just like abstract classes. What is the flaw in this statement?
AInterfaces can contain instance variables only if they are private.
BInterfaces can contain instance variables but cannot modify them.
CAbstract classes cannot contain instance variables, so the comparison is invalid.
DInterfaces can only contain static final variables, not instance variables.
Step-by-Step Solution
Solution:
  1. Step 1: Recall interface variable rules

    Interfaces can declare only static final (constant) variables, no instance variables.
  2. Step 2: Compare with abstract classes

    Abstract classes can have instance variables to hold state.
  3. Step 3: Identify flaw

    Candidate incorrectly assumes interfaces can hold instance state, which is not allowed.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    Interfaces only allow static final variables, no instance state [OK]
Quick Trick: Interfaces cannot hold instance state, only constants [OK]
Common Mistakes:
MISTAKES
  • Confusing static final with instance variables
  • Assuming interfaces behave like classes in state management
  • Believing private variables are allowed in interfaces
Trap Explanation:
PITFALL
  • Candidates conflate interface constants with instance variables, missing key language restrictions.
Interviewer Note:
CONTEXT
  • Tests knowledge of interface variable constraints and state management.
Master "Abstraction - Abstract Class vs Interface - When to Use Which" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes