Monday, April 29, 2013

Published 10:21 PM by with 0 comment

Abstract methods



Abstract methods

When an instance method declaration includes an abstract modifier, that method is said to be an abstract method. Although an abstract method is implicitly also a virtual method, it cannot have the modifier virtual.

An abstract method declaration introduces a new virtual method but does not provide an implementation of that method. Instead, non-abstract derived classes are required to provide their own implementation by overriding that method. Because an abstract method provides no actual implementation, the method-body of an abstract method simply consists of a semicolon.

Abstract method declarations are only permitted in abstract classes

public abstract class AbstractClass
{
public abstract void PrintName();
}

Implementation

public sealed class AbstractImp1:AbstractClass
{
public override void PrintName()
       {
           Console.WriteLine("Im Aruna");
}
}

Calling

AbstractClass abs = new AbstractImp1();
abs.PrintName();

    email this       edit

0 comments: