Language syntax
Java Abstract method
Declares an instance operation without an implementation. A concrete subclass must supply or inherit a suitable implementation.
Formal Syntax & Structure
java syntaxjava
public abstract int fee();Working Example
Example Snippetjava
abstract class Delivery { private final int items; Delivery(int items) { if (items < 0 || items > 100) throw new IllegalArgumentException("items"); this.items = items; } protected int items() { return items; } public abstract int fee();}class Pickup extends Delivery { Pickup(int items) { super(items); } public int fee() { return 0; }}class Courier extends Delivery { Courier(int items) { super(items); } public int fee() { return items() == 0 ? 0 : 100 + 20 * items(); }}public class Main { public static void main(String[] args) { Delivery[] orders = {new Pickup(3), new Courier(3), new Courier(0)}; for (Delivery order : orders) System.out.println(order.fee()); }}