Changing the account balance

Report a typo

There is a class called Account which represents an account in a banking system. It has only a single private field balance, and it is impossible to increase the value of it.

class Account {
    private long balance;

    public Account(long balance) {
        this.balance = balance;
    }

    // some other methods
}

You need to implement the increaseBalance method, which will increase the balance of a given account by a specified amount. Use reflection to solve this problem.

 
Write a program in Java 17
final class AccountUtils {

private AccountUtils() { }

public static void increaseBalance(Account account, long amount) {
// write your code here
}
}
___

Create a free account to access the full topic