Create Static Members

Until now, we have created instance members of classes where every object that is instantiated will have its OWN UNIQUE COPY of all of the properties and methods of that class.  However, you can create static (or shared) members where a property or method is SHARED ACROSS all objects of that class.

EXAMPLE:

Before:

REPLACE LATER WITH OWN SCREENSHOT


NOTE: Multiple objects are instantiated that all have their OWN COPIES of the properties and methods of that class.

After:

However, if you realized that all of the objects need an interest rate, you could define it as a regular property (an instance variable) where every object has its own copy of interest rate.


However, if you want the interest rate to be shared across all saving account even though it might change but not vary from account to account, there is no need to have multiple copies of the property. We can define the interestRate as a static variable (property) which is sometimes called a class-level variable or shared variable as oppose to an instance-level variable where only ONE COPY is shared across all objects.

NOTES: