is it necessary to write abstract method in abstract class code example
Example 1: 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
Example 2: how to make abstract method in java
public abstract class Account {
protected int accountNumber;
protected Customer customerObj;
protected double balance;
public Account(int saccountNumber, Customer scustomerObj,double sbalance){
accountNumber = saccountNumber;
customerObj = scustomerObj;
balance = sbalance;
}
public abstract boolean withdraw(double amount);
}
public class SavingsAccount extends Account {
private double minimumBalance;
public SavingsAccount(int saccountNumber, Customer scustomerObj, double sbalance, double sminimumBalance) {
super(saccountNumber, scustomerObj, sbalance);
minimumBalance = sminimumBalance;
}
public boolean withdraw(double amount) {
if (balance() > minimumBalance && balance() - amount > minimumBalance) {
super.setBalance(balance() - amount);
return true;
} else {
return false;
}
}
}
Example 3: can we have abstract class having no abstract method in java?
abstract class AbstractDemo {
private int i = 0;
public void display() {
System.out.print("Welcome to Tutorials Point");
}
}
public class InheritedClassDemo extends AbstractDemo {
public static void main(String args[]) {
AbstractDemo demo = new InheritedClassDemo();
demo.display();
}
}