6.5. Summary

As with Java interfaces, a C# class can implement multiple interfaces, and C# interfaces can extend each other. However, there are some differences in how the two languages treat the implementation of interfaces. Here are the key points to remember from this chapter:

  • C# does not care which access modifiers are on an interface, even if the interface and the implementing class are in different namespaces. In Java, the interface must be public if it is to be implemented by a class in a different package.

  • A C# class implementing an interface method can have the method declared as public or explicitly declared using C# explicit interface declaration.

  • Through C#'s explicit interface declaration, a class can implement interfaces having common method names, and there can be different implementations for each of the same-named methods. It is the responsibility of the method's caller to indicate the desired implementation by casting the object to the appropriate interface.

  • Explicit interface declaration works only if the method is a member of the interface (that is, the method is directly defined in that interface and not obtained through inheritance of a parent interface).

  • C# provides the as operator to avoid casting.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.144.170