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;
}
}
}
An abstract method is the method which does’nt have any body.
Abstract method is declared with
keyword abstract and semicolon in place of method body.
public abstract void <method name>();
Ex : public abstract void getDetails();
It is the responsibility of subclass to provide implementation to
abstract method defined in abstract class
No, abstract class can have zero abstract methods.
public abstract class Multi{
public abstract void multi();//Abstract method declaration
Public void subtract(){
}
}
No. A normal class(non-abstract class) cannot have abstract methods.
Abstract classes CAN have non-abstract methods.
abstract void display();