13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 20 Interfacesinterface Interface1{void F();}class Class1{public void F() {}public void G() {}}class Class2: Class1, Interface1{new public void G() {}}the method F in Class1 is used in Class2's implementation of Interface1. end example]20.4.3 Interface implementation inheritanceA class inherits all interface implementations provided by its base classes.Without explicitly re-implementing an interface, a derived class cannot in any way alter the interface mappings itinherits from its base classes. [Example: For example, in the declarationsinterface IControl{void Paint();}class Control: IControl{public void Paint() {…}}class TextBox: Control{new public void Paint() {…}}the Paint method in TextBox hides the Paint method in Control, but it does not alter the mapping ofControl.Paint onto IControl.Paint, and calls to Paint through class instances and interface instanceswill have the following effectsControl c = new Control();TextBox t = new TextBox();IControl ic = c;IControl it = t;c.Paint(); // invokes Control.Paint();t.Paint(); // invokes TextBox.Paint();ic.Paint(); // invokes Control.Paint();it.Paint(); // invokes Control.Paint();end example]However, when an interface method is mapped onto a virtual method in a class, it is possible for derived classesto override the virtual method and alter the implementation of the interface. [Example: For example, rewriting thedeclarations above tointerface IControl{void Paint();}class Control: IControl{public virtual void Paint() {…}}289

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!