O'Reilly logo

Learning C# 2005, 2nd Edition by Brian MacDonald, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13: Interfaces

Quiz

Solution to Question 13–1.

The interface defines the methods, properties, etc. that the implementing class must provide. The implementing class provides these members and, optionally, additional members.

Solution to Question 13–2.

Every class has exactly one base class, but may implement zero, one, or more interfaces. An abstract base class serves as the base to a derived class that must implement all its abstract methods or that derived class is also abstract.

Solution to Question 13–3.

class MyClass : MyBase, ISuppose, IDo {}

Note that the base class must come first after the colon.

Solution to Question 13–4.

The is and the as operator.

Solution to Question 13–5.

is returns false if the interface is not implemented; as returns null. Using the as operator can be more efficient.

Solution to Question 13–6.

Extending an interface is very much like deriving a class. The new interface inherits all the members of the parent interface, and can also include additional methods.

Solution to Question 13–7.

ExtendedInterface : OriginalInterface

For example, read:

ILoggedCompressible : ICompressible

as “ILoggb[edCompressible extends ICompressible.”

Solution to Question 13–8.

The class implementing a method of the interface can mark that method virtual, and the implementation of the method can be overridden in derived classes.

Solution to Question 13–9.

Explicit interface implementation identifies the member of the interface by naming the interface itself (e.g., IStorable.Write( )). This ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required