2 <clause number="8.7.11" title="Inheritance" informative="true">
3 <paragraph>Classes support single inheritance, and the type object is the ultimate base class for all classes. </paragraph>
4 <paragraph>The classes shown in earlier examples all implicitly derive from object. The example <code_example><![CDATA[
8 public void F() { Console.WriteLine("A.F"); }
10 ]]></code_example>shows a class A that implicitly derives from object. The example <code_example><![CDATA[
13 public void G() { Console.WriteLine("B.G"); }
19 b.F(); // Inherited from A
20 b.G(); // Introduced in B
22 A a = b; // Treat a B as an A
26 ]]></code_example>shows a class B that derives from A. The class B inherits A's F method, and introduces a G method of its own. </paragraph>
27 <paragraph>Methods, properties, and indexers can be virtual, which means that their implementation can be overridden in derived classes. The example <code_example><![CDATA[
31 public virtual void F() { Console.WriteLine("A.F"); }
35 public override void F() {
37 Console.WriteLine("B.F");
49 ]]></code_example>shows a class A with a virtual method F, and a class B that overrides F. The overriding method in B contains a call, base.F(), which calls the overridden method in A. </paragraph>
50 <paragraph>A class can indicate that it is incomplete, and is intended only as a base class for other classes, by including the modifier abstract. Such a class is called an abstract class. An abstract class can specify abstract members-members that a non-abstract derived class must implement. The example <code_example><![CDATA[
54 public abstract void F();
58 public override void F() { Console.WriteLine("B.F"); }
69 ]]></code_example>introduces an abstract method F in the abstract class A. The non-abstract class B provides an implementation for this method. </paragraph>