// Instance members to get/set interest rate.
public void SetInterestRateObj(double newRate)
{ currInterestRate = newRate; }
public double GetInterestRateObj()
{ return currInterestRate; }
...
}
Here, SetInterestRateObj() and GetInterestRateObj() are operating on the same static field
as the static SetInterestRate()/GetInterestRate() methods. Thus, if one object were to change the
interest rate, all other objects report the same value:
static void Main(string[] args)
{
Console.WriteLine("***** Fun with Static Data *****\n");
SavingsAccount.SetInterestRate(0.09);
SavingsAccount s1 = new SavingsAccount(50);
SavingsAccount s2 = new SavingsAccount(100);
Do'stlaringiz bilan baham: |