Write a program to test class
SavingsAccount. Instantiate two savingsAccount objects, saver1 and saver2, with
balances of Rs 2000.00 and Rs 3000.00, respectively. Set annualInterestRate to
4%, then calculate the monthly interest and print the new balances for both
savers. Then set the annualInterestRate to 5%, calculate the next month's
interest and print the new balances for both savers.
Introduction:
Constructor in java is a special type of method that is used
to initialize the object. Java constructor is invoked at the time of
object creation. It constructs the values i.e. provides data for the
object that is why it is known as constructor
There are two types of constructors:
· Default constructor
(no-arg constructor)
· Parameterized constructor
Method Overloading:
If a class has multiple
methods having same name but different in parameters, it is known as Method
Overloading.If we have to perform only one operation, having same name
of the methods increases the readability of the program.Suppose you have to
perform addition of the given numbers but there can be any number of arguments,
if you write the method such as a for two parameters, and b(int,int,int) for
three parameters then it may be difficult for you as well as other programmers
to understand the behavior of the method because its name differs.So, we
perform method overloading to figure out the program quickly.
Method overriding:
If subclass (child class) has the
same method as declared in the parent class, it is known as method
overriding in java.In other words, If subclass provides the specific
implementation of the method that has been provided by one of its parent class,
it is known as method overriding.
out put
Enter Your name:
ajay
Enter Your Account Number:
12345
Your balance is:2000
Monthly interest is:666
Balance is:2666
Enter Your name:
vijay
Enter Your Account Number:
23456
Your balance is:3000
Monthly interest is:1250
Balance is:4250
Enter Your name:
gaja
Enter Your Account Number:
4523
Your balance is:3000
Monthly interest is:1250
Balance is:4250