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 correctly?

Aclass File : IReadable, IWritable { public void Read() {} public void Write() {} }
Bclass File : IReadable { public void Read() {} } class File : IWritable { public void Write() {} }
Cclass File : IReadable & IWritable { public void Read() {} public void Write() {} }
Dclass File implements IReadable, IWritable { public void Read() {} public void Write() {} }
Step-by-Step Solution
Solution:
  1. Step 1: Recall C# syntax for multiple interface implementation

    Use colon ':' followed by comma-separated interface names.
  2. Step 2: Check syntax options

    The correct syntax is 'class File : IReadable, IWritable { ... }'. Using 'implements' keyword is Java syntax, not C#; declaring the same class twice is invalid; using '&' between interfaces is incorrect.
  3. Final Answer:

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

    Multiple interfaces use ':' and commas [OK]
Quick Trick: Use ':' and commas to implement multiple interfaces [OK]
Common Mistakes:
MISTAKES
  • Using 'implements' keyword
  • Trying to declare class twice
  • Using '&' for interfaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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