public abstract class Shape {
    // Abstract method without implementation
    public abstract double area();

    // Concrete method with implementation
    public void display() {
        System.out.println("This is a shape.");
    }
}Sometimes we may come across a situation where we cannot provide 
implementation to all the methods in a class. We want to leave the 
implementation to a class that extends it. In such case we declare a class
as abstract.To make a class abstract we use key word abstract. 
Any class that contains one or more abstract methods is declared as abstract. 
If we don’t declare class as abstract which contains abstract methods we get 
compile time error.
  
  1)Abstract classes cannot be instantiated
  2)An abstract classes contains abstract method, concrete methods or both.
  3)Any class which extends abstract class must override all methods of abstract
    class
  4)An abstract class can contain either 0 or more abstract method.    public abstract class Animal {
    private String name;

    public Animal(String name) {
        this.name = name;
    }

    public void eat() {
        System.out.println(name + " is eating.");
    }

    public abstract void makeSound(); // Abstract method
}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/*Abstract class:
A class which is declared as abstract is known as an abstract class. 
It can have abstract and non-abstract methods. It needs to be extended 
and its method implemented. It cannot be instantiated.

*/

// Example of abstract class
abstract class A{}  
// Example of Abstract class that has an abstract method
abstract class Bike{  
  abstract void run();  
}  
class Honda4 extends Bike{  
void run(){System.out.println("running safely");}  
public static void main(String args[]){  
 Bike obj = new Honda4();  
 obj.run();  
}  
}  /**
 * Simple Java program to prove that abstract class can have constructor in Java.
 * @author http://java67.blogspot.com
 */
public class AbstractConstructorTest {

    public static void main(String args[]) {
       Server server = new Tomcat("Apache Tomcat");
       server.start();
    }
}

abstract class Server{
    protected final String name;
   
    public Server(String name){
        this.name = name;
    }
   
    public abstract boolean start();
}

class Tomcat extends Server{
   
    public Tomcat(String name){
        super(name);
    }

    @Override
    public boolean start() {
       System.out.println( this.name + " started successfully");
       return true;
    }
   
}

Output:
Apache Tomcat started successfully

interface methods{
    public void hey();
    public void bye();
}

//unable to implement all the abstract methods in the interface so 
// the other class automatically becomes abstract
abstract class other implements methods{
    public void hey(){
        System.out.println("Hey");
    }
}

//able to implement all the methods so is not abstract
class scratch implements methods {
    public void hey(){
        System.out.println("Hey");
    }
    public void bye() {
        System.out.println("Hey");
    }
}abstract class Language {

  // method of abstract class
  public void display() {
    System.out.println("This is Java Programming");
  }
}

class Main extends Language {
  public static void main(String[] args) {
    
    // create an object of Main
    Main obj = new Main();

    // access method of abstract class
    // using object of Main class
    obj.display();
  }
}abstract class scratch{
  
}Abstract classes have some special features:

it's impossible to create an instance of an abstract class;
an abstract class can contain abstract methods that must be implemented in non-abstract subclasses;
it can contain fields and non-abstract methods (including static);
an abstract class can extend another class, including abstract;
it can contain a constructor.

Java相关代码片段

my image is not found java fx

pom.xml JUnit 5 dependencies

java set difference

regex for first name only

StringBuffer(CharSequence seq)

array class methods in java

how to read all line from file java

Java int length

intent example in android

how to doubling size of an arrays in java

how to find my jdk path

how to handle multiple throws exception in java

spring boot jdbc for postgrest

factorial of a number

types of typecasting in java

types of assignment statement in java

Thread mutex

env files in spring boot

java over loading

logging in spring boot

how to split a list in multiple lists java

can two servlet have same urlpattern

spring debug

jsp spring

hanoi tower recursion java

java equals

age difference java

sed cheat sheet

java compare method

how to make a activity default in manifest

java max memory size

yum uninstall java

timestamp to long java

how to set background image in android studio

simple calculator in android

When to use HashMap vs Map

spring boot jpa

spring data jpa

spring jdbc

jpa vs hibernate

java with checking the password matching

profile in spring boot

string templates java

spring rest controller

java arraylist get item

com.oracle.jdbc

check if map is not empty java

how to install java 8 on debian 12

regex caractères spéciaux java

java 11 yum install

manage session in redis spring boot

java: error: release version 19 not supported

bean scope in spring

xml configuration in spring

spring cdi annotations

postconstruct and predestroy in spring

java decode_message

spring lazy initialization

java decorator design pattern

dependency injection in spring

check back pressed in fragment andorid

send email to any domain using java

record java

vs code setup for input/output in java

substring java

receive second word in string java

loose coupling in java

default value of char in java

spring boot repository pattern

spring boot h2 database

add security to spring admin

java islessthan method

Java implementation of recursive Binary Search

java round double

java downcasting

range of fibonacci series in java using recursion

java by anyone

solid java

equals() and hashcode() methods in java

android java map to bundle