C# & Inheritance

mike55

Contributor
Joined
Mar 26, 2004
Messages
727
Location
Ireland
I am messing with C# at the moment, I am after creating an account class which has a balance and an account holder. It also has methods to lodge, withdraw, getbalance, and getholdersName.

In the constructor section I have Account() and Account(string name, double balance) which should allow me to create a blank account or an account with existing data.

I have also set the lodge and withdraw method to be overrideable. I then created a class called AdvancedAccount that inherits from Account, that has a method that overrides the account.lodge method.

Everything works correctly from the main class if I go AdvancedAccount a = new AdvancedAccount();

I cannot however seem to create an account with which I can pass in the holders name and balance.

Any suggestions?

Mike55.
 
When you inherit from a class you do not inherit it's constructors - you would need to provide the relevant ones for the AdvancedAccount class; these could simply call the base classes version though.
 
What PD said. Here's a sample:
C#:
public class AdvancedAccount(string name, double balance) : base(name, balance)
{
// Nothing needed here - the call to base is done above
}

-ner
 
Back
Top