Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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;
        }
    }
}

Comment

What are abstract methods in java

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
Comment

is it necessary for abstract class to have abstract method

No, abstract class can have zero abstract methods.
Comment

Abstract method declaration

public abstract class Multi{
public abstract void multi();//Abstract method declaration
Public void subtract(){
}
}
Comment

can you declare an abstract method in a non abstract class

No. A normal class(non-abstract class) cannot have abstract methods.
Comment

is it necessary for abstract class to have abstract method

Abstract classes CAN have non-abstract methods. 
Comment

Java Abstract Method

abstract void display();
Comment

PREVIOUS NEXT
Code Example
Java :: spring properties list 
Java :: java object into list 
Java :: java how to change the length of an array 
Java :: check if duplicate element in java 
Java :: Remove an element at a specific index from an array in Java 
Java :: float to int in java 
Java :: How to activate an entity listener for all entities 
Java :: java break and continue 
Java :: android studio clock bar change color programmatically 
Java :: initializing list in java 
Java :: separateur JMenu swing java 
Java :: new thrad java 
Java :: How to get the nth Fibonacci number code in Java using recursion with memoization 
Java :: sort list of list java 
Java :: get free player inventory slots spigot 
Java :: Button loginButton = new Button(this); loginButton.setText("Login"); Button register Button = new Button(this); register Button .gettext("Register"); 
Java :: default case in Java switch-case 
Java :: how to create a subclass in java 
Java :: set gamemode of player spigot 
Java :: make quotation a string 
Java :: java new string 
Java :: java run class file 
Java :: date java use fix timezone 
Java :: area of rectangle in java 
Java :: Java comment vérifier une égalité de String 
Java :: java long data type 
Java :: java infinite for loop 
Java :: search 
Java :: java double 
Java :: What would be the behavior if this() and super() used in a method? 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =