Wednesday, October 7, 2015

Concrete, Abstract, Virtual and Sealed

Concrete class;
  1. Standard class that we write our methods
  2. Cannot contain abstract methods
  3. Can be used as base class or child class
  4. Can create object and call methods
Abstract class;
  1. It is declared with the keyword abstract
  2. Must be used only as a base class. i.e, cannot create object like concrete class
  3. Cannot create instance of class.
  4. Can contain abstract methods as well as concrete (standard) methods
Abstract method;
  1. An abstract member cannot provide any implementation. It is only a method definition.
  2. You must implement (override) using the keyword override in your child class with your own functionality when you derive the class that contains this method.
  3. An abstract member is implicitly virtual.
  4. Can only reside inside an abstract class
Virtual method; 
  1. A method which does something.
  2. You may either override with your own functionality or not. It is not a must to override.
  3. It is recommended to use the keyword override when doing so. Because, it will work without the override keyword also.
Sealed class;
  1. Is used to restrict a class from being inherited.
Sealed method;
  1. You can only make a method sealed for an overridden method.
  2. You seal a method to prevent making any changes to it in the derived classes.

No comments:

Post a Comment