I\'m having an error message that tells me this:
\'BankAccount.account\' does not contain a definition for \'withdraw\'.
Here\'s my code:
using S
I assume your intention was to define the basic withdraw
method in the base account
class, so that it would be inherited by both savingaccount
and currentaccount
. You should declare it as virtual
in order to allow it to be overridden by the derived classes, if required.
class account
{
public virtual void withdraw(float amt)
{
if (balance - amt < 0)
Console.WriteLine("No balance in account.");
else
balance -= amt;
}
}
The currentaccount
class presumably does not need to modify the logic of this inherited method, so you can omit it altogether. On the other hand, in your savingaccount
class, you can override the method to implement your custom behaviour:
class savingaccount : account
{
public override void withdraw(float amt)
{
if (trans >= 10)
{
Console.WriteLine("Number of transactions exceed 10.");
return;
}
if (balance - amt < 500)
Console.WriteLine("Below minimum balance.");
else
{
base.withdraw(amt);
trans++;
}
}
}