Can abstract methods have static keyword
No, abstract method is a method that's meant to be overridden,
only the instance methods can be override
Can abstract methods have static keyword
No, abstract method is a method that's meant to be overridden,
only the instance methods can be override
how to make abstract method in java
public abstract class Account { //abstract class //perent class
protected int accountNumber;
protected Customer customerObj;
protected double balance;
//constructor
public Account(int saccountNumber, Customer scustomerObj,double sbalance){
accountNumber = saccountNumber;
customerObj = scustomerObj;
balance = sbalance;
}
// abstract Function
public abstract boolean withdraw(double amount);
}
public class SavingsAccount extends Account { // child class
private double minimumBalance;
// constructor
public SavingsAccount(int saccountNumber, Customer scustomerObj, double sbalance, double sminimumBalance) {
super(saccountNumber, scustomerObj, sbalance);
minimumBalance = sminimumBalance;
}
// Implementation of abstract function in child class
public boolean withdraw(double amount) {
if (balance() > minimumBalance && balance() - amount > minimumBalance) {
super.setBalance(balance() - amount);
return true;
} else {
return false;
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us