Sunday, November 29, 2009

executing parameterless base constructor for initializing some attributes of base class

Suppose you have a bank account class.from which you will generate
two classes-savings account & checking account.each one has other
attributes besides common base class attributes.

suppose common 'balance' attribute of base class needed to be
initialized to 0 then you will do that by the base  parameterless
constructor of the base class as the following way -

public abstract class BankAccount
    {
        private string accountNumber;
        private string customerName;
        private double balance;

        public BankAccount(string accountNumber, string customerName) : this()
        {
            this.accountNumber = accountNumber;
            this.customerName = customerName;
        }
       
       // here is the first constructor for initializing balance

        public BankAccount()
        {
            this.balance = 0;
        }
}

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger