Example #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Simple Saving Account Class");

            //three instances of SavingAccount

            SavingsAccount s1 = new SavingsAccount(50);

            SavingsAccount s3 = new SavingsAccount(10000.75);

            Console.WriteLine($" Interest Rate is {SavingsAccount.GetInterestRate()}");


            /**
             *  The static data is shared by all objects of same
             *  category meaning .. currInterestRate is same for
             *  all savingAccount s1,s2 and s3 or any other created
             */

            //pring the current InterestRate
            Console.WriteLine($" Interest Rate is {SavingsAccount.GetInterestRate()}");
            SavingsAccount.SetInterestRate(0.8);

            SavingsAccount s4 = new SavingsAccount(10000.75);

            Console.WriteLine($" Interest Rate is {SavingsAccount.GetInterestRate()}");
            SavingsAccount s2 = new SavingsAccount(100);

            Console.WriteLine($" Interest Rate is {SavingsAccount.GetInterestRate()}");


            // Calling Static Class
            TimeUtilClass.PrintDate();
            TimeUtilClass.PrintTime();
        }
Example #2
0
        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();
            Console.WriteLine("***** Fun with Static Classes *****\n");

            // This is just fine.
            TimeUtilClass.PrintDate();
            TimeUtilClass.PrintTime();

            // Compiler error! Can't create instance of static classes!
            //TimeUtilClass u = new TimeUtilClass ();

            Console.ReadLine();
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data *****\n");
            // SavingsAccount s1 = new SavingsAccount(50);
            // SavingsAccount s2 = new SavingsAccount(100);
            // SavingsAccount s3 = new SavingsAccount(10000.75);

            // SavingsAccount s1 = new SavingsAccount(50);
            // SavingsAccount s2 = new SavingsAccount(100);
            //
            // Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());
            //
            // SavingsAccount s3 = new SavingsAccount(10000.75);
            // Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            //  SavingsAccount s1 = new SavingsAccount(50);
            //
            //  Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());
            //
            //  SavingsAccount.SetInterestRate(0.08);
            //
            //  SavingsAccount s2 = new SavingsAccount(100);
            //
            // Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            TimeUtilClass.PrintDate();
            TimeUtilClass.PrintTime();

            //TimeUtilClass u = new TimeUtilClass();

            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.InterestRate);

            Console.ReadLine();
        }