static void Main(string[] args) { Console.WriteLine("***** Fun with Static Data *****\n"); TimeUtilClass.PrintDate(); // Compiler error! Can't create static classes. // TimeUtilClass u = new TimeUtilClass(); SavingsAccount.SetInterestRate(0.09); SavingsAccount s1 = new SavingsAccount(50); SavingsAccount s2 = new SavingsAccount(100); // All three lines print out "Interest Rate is: 0.09" Console.WriteLine("Interest Rate is: {0}", s1.GetInterestRateObj()); Console.WriteLine("Interest Rate is: {0}", s2.GetInterestRateObj()); Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate()); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Static Data *****\n"); SavingsAccount s1 = new SavingsAccount(50); SavingsAccount s2 = new SavingsAccount(100); // Print the current interest rate. Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate()); // Make new object, this does NOT 'reset' the interest rate. SavingsAccount s3 = new SavingsAccount(10000.75); Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate()); Console.WriteLine(); // This is just fine. TimeUtilClass.PrintDate(); TimeUtilClass.PrintTime(); Console.ReadLine(); }