Amita Palkar - Junnarkar
Why abstract class used as base class over normal class
By Amita Palkar - Junnarkar in C# on Mar 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
  • Munib Butt
    Apr, 2020 28

    We normally declare a base class as an abstract class when we want to define a template for a number of classes. This template than has to be used with some extension in the derived classes. However, we do not want the template class or abstract class to be used directly.

    • 0
  • 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.

    • 0

Most Popular Job Functions