Defining Static Constructors
As explained earlier in this chapter, constructors are used to set the value of a type’s data at the time
of creation. Thus, if you were to assign a value to a static data member within an instance-level con-
structor, you may be surprised to find that the value is reset each time you create a new object! For
example, assume you have updated the SavingsAccount class as follows:
class SavingsAccount
{
public double currBalance;
public static double currInterestRate;
public SavingsAccount(double balance)
{
Do'stlaringiz bilan baham: |