Friday 23 November 2012

Abstract classes




1. They are classes that cannot be instantiated.
2. Either partially implemented, or not at all implemented.
3. One key difference between abstract classes and interfaces is that a class may implement an unlimited number of interfaces,
but may inherit from only one abstract (or any other kind of) class.
4. A class that is derived from an abstract class may still implement interfaces
5. In C#, the abstract modifier is used
6. Any methods that are to be implemented are marked as abstract
7. eg:
abstract class WashingMachine
{
  public WashingMachine()
  {
 // Code to initialize the class goes here.
  }

  abstract public void Wash();
  abstract public void Rinse(int loadSize);
  abstract public long Spin(int speed);
}
8. A class inheriting from this class would have to implement the Wash, Rinse, and Spin methods
9. eg:

class MyWashingMachine : WashingMachine
{
  public MyWashingMachine()
  {
 // Initialization code goes here.  
  }

  override public void Wash()
  {
 // Wash code goes here.
  }

  override public void Rinse(int loadSize)
  {
 // Rinse code goes here.
  }

  override public long Spin(int speed)
  {
 // Spin code goes here.
  }
}
10. When implementing an abstract class, you must implement each abstract (MustOverride) method in that class
11. Each implemented method must receive the same number and type of arguments, and have the same return value, as the method specified in the abstract class.




No comments:

Post a Comment

IE7 Issues Text Indent

                 Unfortunately IE 7 is still widespread among the users hence while theming we have to give special importance to the grea...