X hits on this document

1067 views

0 shares

0 downloads

0 comments

241 / 396

C# LANGUAGE SPECIFICATION

public abstract class Shape { public abstract void Paint(Graphics g, Rectangle r); }

public class Ellipse: Shape { public override void Paint(Graphics g, Rectangle r) { g.DrawEllipse(r); } }

public class Box: Shape { public override void Paint(Graphics g, Rectangle r) { g.DrawRect(r); } }

the Shape class defines the abstract notion of a geometrical shape object that can paint itself. The Paint method is abstract because there is no meaningful default implementation. The Ellipse and Box classes are concrete Shape implementations. Because these classes are non-abstract, they are required to override the Paint method and provide an actual implementation.

It is a compile-time error for a base-access (§‎7.5.8) to reference an abstract method. In the example

abstract class A { public abstract void F(); }

class B: A { public override void F() { base.F();// Error, base.F is abstract } }

a compile-time error is reported for the base.F() invocation because it references an abstract method.

An abstract method declaration is permitted to override a virtual method. This allows an abstract class to force re-implementation of the method in derived classes, and makes the original implementation of the method unavailable. In the example

using System;

class A { public virtual void F() { Console.WriteLine("A.F"); } }

abstract class B: A { public abstract override void F(); }

228Copyright Microsoft Corporation 1999-2003. All Rights Reserved.

Document info
Document views1067
Page views1067
Page last viewedSat Dec 10 20:40:22 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments