The characteristic of OOP in the code is encapsulation, which protects data by bundling it with methods that control access. Methods such as getBalance , deposit , and withdraw exemplify this concept. Encapsulation ensures that balance changes are managed safely to maintain data integrity.
;
i) One characteristic of Object-Oriented Programming (OOP) applied to the above methods is overloading . Method overloading allows multiple methods to have the same name but different parameter lists within the same class.
ii) Three method headers that relate to method overloading could be:
public void deposit(double amount)
public void deposit(int amount)
public void deposit(String amount)
These methods demonstrate overloading by having the same method name 'deposit' but different parameter types (double, int, String).
iii) Method overloading is an OOP concept where two or more methods in a class have the same name but different parameters. This allows methods to perform similar or related functions on different types or numbers of input data.
In the provided code segment, overloading is demonstrated in the constructors of the BankAccount class. There are three constructors: one with no parameters that initializes the balance to 0.0, one that initializes the balance with a double value, and another that initializes the balance from a String that is parsed to a double. These demonstrate overloading as they share the same name 'BankAccount' but have different parameter lists, allowing the creation of BankAccount objects in different ways depending on the needs.