Search code examples
c#abstract-classabstract-methods

Abstract methods in c#


I honestly don't know why this is throwing me off.

 public abstract class BankAccount
    {
        private string accNo;
        private double balance;


        public abstract void MakeWithdrawal(string acc);
        public abstract void MakeDeposit(double dep);

The above code is throwing this error:

BankAccount.MakeWithdrawal()' is abstract but it is contained in non-abstract class 'Worksheet7.BankAccount'

This is even though i declared the class as abstract. Is there something I'm missing here or a perquisite in visual studio I'm missing?


Solution

  • I suspect that you have some other class called BankAccount in the Worksheet7 namespace which is not defined as abstract. The following code compiles just fine:

    public abstract class BankAccount
    {
        private string accNo;
        private double balance;
    
        public abstract void MakeWithdrawal(string acc);
        public abstract void MakeDeposit(double dep);
    }
    

    So the error message is not on this class. It is on another class with the same name defined in a different namespace.