What is the Abstract Class in C#?

Abstract class in C#

The abstract class is a special privileged class in the C#. This will provide a blueprint for the derived classes with a setup of rules and instructions to be derived. The abstract class contains both abstract and non-abstract methods.

Abstract Class Example

 public abstract class employeeBenifts
    {
        public abstract decimal PhoneMinimumbill();
        public abstract decimal InternetMinMill();
    }

    public class FulltimeEmployee : employeeBenifts
    {
        public override decimal PhoneMinimumbill()
        {
            return 100;
        }

        public override decimal InternetMinMill()
        {
           return 600;
        }
    }

    public class EmployeeBillSubmission
    {
        FulltimeEmployee fulltimeEmployee;
        public EmployeeBillSubmission()
        {
            fulltimeEmployee = new FulltimeEmployee();
        }

        void SubmitBill(BillSubmissionModel request)
        {
            //Logic will change based on the requirement

            if (request.InternetBill < 500)
                request.InternetBill = fulltimeEmployee.InternetMinMill();

            if (request.PhoneBill < 500)
                request.PhoneBill = fulltimeEmployee.PhoneMinimumbill();

            //save the Request into the DB. DB insertion logic need to perform
        }
    }

    public class BillSubmissionModel
    {
        public string EmployeeId { get; set; }
        public string Month { get; set; }

        public decimal PhoneBill { get; set; }
        public decimal InternetBill { get; set; }
    }

What is the use of the abstract class in c#?

In object-oriented programming Abstraction is one of the key features. With the help of abstract keywords, you can archive the Abstraction. In general, data abstraction is the process of hiding unwanted data and showcasing the necessary data to the user.

  • An abstract class provides a blueprint and set of instructions to override.
  • It can’t be directly initialized.
  • Inherited to the derived class and initialize and create an object for derived classes.


Similar Articles