Abstract Class features

  • class members that are incomplete and must be implemented in a derived class.
  • An abstract class cannot be instantiated.
  • The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share.
  • Abstract classes may also define abstract methods.

public abstract class A
public abstract void DoWork(int i);

  • Derived classes of the abstract class must implement all abstract methods.
  • When an abstract class inherits a virtual method from a base class, the abstract class can override the virtual method with an abstract method.
  • We can also inherit normal method in the abstract class and declare it as abstract, though it compiles it shows warning that abstract method must be virtual.

public class D
public virtual void DoWork(int i)
// Original implementation.

public abstract class E : D
public abstract override void DoWork(int i);

public class F : E
public override void DoWork(int i)
// New implementation.

  • If a virtual method is declared abstract, it is still virtual to any class inheriting from the abstract class.
  • A class inheriting an abstract method cannot access the original implementation of the method.
  • override keyword  should be used while defining abstract method in derived class.

Ref:- http://msdn.microsoft.com/en-us/library/yd3z1377.aspx

Tagged: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: