Bird
Raised Fist0

You have two interfaces:

hard🚀 Application Q8 of Q15
C Sharp (C#) - Interfaces
You have two interfaces:
interface IReadable { void Read(); }
interface IWritable { void Write(); }
How can a class File implement both interfaces and provide separate implementations for each method?
Aclass File : IReadable { void Read() { } } class File : IWritable { void Write() { } }
Bclass File : IReadable, IWritable { public void Read() { } public void Write() { } }
Cclass File : IReadable, IWritable { void Read() { } void Write() { } }
Dclass File : IReadable, IWritable { private void Read() { } private void Write() { } }
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple interface implementation syntax

    Use comma-separated interfaces after class name.
  2. Step 2: Implement all interface methods as public

    Methods must be public and implemented in the class.
  3. Final Answer:

    class File : IReadable, IWritable { public void Read() { } public void Write() { } } -> Option B
  4. Quick Check:

    Multiple interfaces implemented with public methods [OK]
Quick Trick: Separate interfaces with commas and implement all methods publicly [OK]
Common Mistakes:
MISTAKES
  • Trying to declare class twice for each interface
  • Omitting public keyword on methods
  • Making methods private

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes