All about Abstract Class

What is abstract class?

A classes cannot initialize are called the abstract class. Abstract Classes are incomplete classes, means it will have both combination of implemented and unimplemented method with the properties, index, member, events and delegates. Use the abstract modifier in a class declaration to indicate that a class is made only to be a base class of other classes. We can declare any no of abstract methods in abstract class, but whenever you inherit this class into child class you must be implemented those abstract methods in your child class; otherwise complier gives an error in this case.

Why we use Abstract Class?

 The mail idea to have class as abstract is to provide the flexibility to derived classes to implement as per requirement. Abstract method does not provide an implementation and force to derived class to override this method.

When we use Abstract Class?

If you are creating something for objects that are closely related in a hierarchy, use an abstract class. Abstract classes allow you to provide default functionality for the derived classes. If you plan on updating this base class throughout the life of your program, it is best to allow that base class to be an abstract class. Why? Because you can make a change to it and all of the inheriting classes will now have this new functionality.

Rules of Abstract Class

  •  Abstract Class cannot be initialized.
  • If you have parameterized constructor in Abstract Class so you must have a default Constructor.
  • Abstract Class cannot have private constructor.
  • Abstract Method must be public
  • Abstract Class must be implemented by a non-abstract class or abstract class.
  • An Abstract Class can implement the abstract method of parent abstract class.