站内搜索: 请输入搜索关键词
当前页面: 图书首页 > NET For Java Developers Migrating To C#

NET For Java Developers Migrating To C#

[ directory ] Previous Section Next Section

Chapter 6. Implementing Interfaces

An interface defines a protocol of behavior that can be implemented by any class anywhere in the class hierarchy. An interface defines a set of methods but does not implement them. A class that implements the interface agrees to implement all the methods defined in the interface, thereby agreeing to certain behavior.

Because an interface is simply a list of unimplemented methods you might wonder how an interface differs from an abstract class. The differences are significant:

  • An interface cannot implement any methods, whereas an abstract class can.

  • A class can implement many interfaces but can have only one superclass.

  • An interface is not part of the class hierarchy.

  • Unrelated classes can implement the same interface.

Let's look at C# interfaces more closely.

    [ directory ] Previous Section Next Section