Abstract Class in C#

“An abstract is implement that the class is incomplete and can’t be use directly, to use an abstract class other class can derived.”

An abstract class contains abstract method which can be implemented by the

Example

  1. using System;
  2. abstract class Animal
  3. {
  4. public abstract void FoodHabits();
  5. }
  6. class Carnivorous:Animal
  7. {
  8. public override void FoodHabits()
  9. {
  10. Console.WriteLine("The Carnivorous Animal Eat Only Meat");
  11. }
  12. }
  13. class Herbivorous:Animal
  14. {
  15. public override void FoodHabits()
  16. {
  17. Console.WriteLine("The Harbivorous Animal Eat Only Plants");
  18. }
  19. }
  20. class Implement
  21. {
  22. public static void Main()
  23. {
  24. Carnivorous cn = new Carnivorous();
  25. Herbivorous hb = new Herbivorous();
  26. cn.FoodHabits();
  27. hb.FoodHabits();
  28. Console.ReadLine();
  29. }
  30. }
See the output below