I have a class called BankAccount
with 2 constructors, one with no argument and the second take an int as a parameter:
public final class BankAccount {
private int balance;
public String name;
public BankAccount() {
}
public BankAccount(int startBalance) {
balance = startBalance;
}
}
so when I try to create an object using the constructor with the integer param like this :
try {
BankAccount account = BankAccount.class.getConstructor(Integer.class).newInstance(100);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I get the exception of NosuchMethodException
.