I'm new to programming and this class-things are doing my head in.
Here is my code (type is based on userinput)
public static Account CreateAccount(int type)
{
switch (type)
{
case 1:
SaveAcc savings = new SaveAcc();
break;
default:
Console.WriteLine("No such choice");
break;
}
return new Account();
}
These are my classes:
class Account
{
protected int balance;
protected int accountnr = 1;
protected bool credit;
public Account()
{
newNr++;
accountnr = newNr;
}
public override string ToString()
{
return "AccNr: " + Nr.ToString("G") + ", balance: " + balance.ToString("C");
}
}
class SaveAcc: Account
{
public int rate;
public SaveAcc()
{
credit = true;
rate = 0.03;
}
public override string ToString()
{
return "AccNr: " + Nr.ToString("G") + ", balance: " + balance.ToString("C") + credit.ToString();
}
}
When I create a SavAcc object the "wrong" override is being called. My goal is to display all the information given by the override ToString method located in the SavAcc inherited class. Am I missing something obvious?