Monday, July 23, 2012

Abstract - Key things about Abstract Classes/Methods

Abstract Classes
  • An Abstract class cannot be instantiated.
abstract class SampleAbs
{
...
}
SampleAbs instance = new SampleAbs(); // Compile Error
  • It cannot be modified with the 'sealed' modifier. In other words, an Abstract Class should be inherited.
  • An Abstract class may contain abstract as well as non abstract members.

Abstract Methods
  • An Abstract method cannot contain a method body.
abstract class AbsClass
{
abstract void AbsMethod(); // Legal

abstract void AbsMethod()
{
... // Illegal
}
}
  • An abstract method is implicitly a virtual method.
  • An Abstract method can only be added in an Abstract Class.

No comments:

Post a Comment