.

Monday, January 5, 2009

Abstract Methods in C# .NET

An abstract method is a virtual method with no implementation. The actual implementation of the abstract method will be from a overridden method of the derived class.

An abstract method is declared with the abstract modifier and is permitted only in a class that is also declared abstract.

public abstract class AbsExample {

public abstract string AbsMethod();

}

An abstract method must be overridden in every non-abstract derived class.

class AbsImplementor : AbsExample

{

public override string AbsMethod()

{

//code here...

return "AbsMethod Implemented!!!";

}

}


The method can be invoked by...

AbsImplementor a1 = new AbsImplementor();

Console.WriteLine(a1.AbsMethod());

No comments:

.