Interviews - C# Corner

Amita Palkar - Junnarkar
Why abstract class used as base class over normal class
By Amita Palkar - Junnarkar in C# onMar 23 2018
  • Gajanan Chavhan
    Apr, 2018 10

    This can be explained best by using area of regular polygon. Regular polygon is polygon with all sides with equal length. Perimeter of polygon can be calculated by using sideLength*NumberOfSides and it is applicable for all polygon. But calculating area is different of each shape. in this case we can make polygon class as abstract class with GetPerimter() method as concentrate method and making Area method as abstract method that can be implemented by derived classes. for example square class should have it's own implementation of Area method and equilateral trangle should have it's own implementation.

    • 5
  • Pravinkumar Birajdar
    Apr, 2018 10

    If we want to implement common functionality to classes, we use interface. As compared to interfaces with abstract class, it can also have implemented.but without implantation an abstract class does same thing as interface. We can extend abstract class as long as we dont change its method signature.***in short, we have to implement common functionality to child classes, but base class doesn't need implementation then base class should be abstract***

    • 5
  • Shivam Shukla
    Jun, 2018 27

    "When the base class is a normal class ( i.e. not an abstract class), then wouldn't the base class be automatically instantiated ..."When a derived class is instantiated a single memory allocation is made. That allocation is used to store all the fields of the derived class and all other classes in its inheritance chain, there is no distinct memory allocation made for any base class.https://social.msdn.microsoft.com/Forums/vstudio/en-US/f4426460-43be-43e5-a897-68a9fa77b7c4/any-performance-benefit-in-using-an-abstract-class-instead-of-normal-class-for-a-base-class?forum=csharpgeneral

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS