Language syntax

Java Class extends

Declares a direct superclass. Accessible operations can be inherited, while constructors are not inherited. Final classes cannot be extended.

Formal Syntax & Structure

java syntaxjava
class ExpressParcel extends Parcel

Working Example

Example Snippetjava
class Parcel {    private final int weight;    Parcel(int weight) {        if (weight <= 0 || weight > 100) throw new IllegalArgumentException("weight");        this.weight = weight;    }    public int weight() { return weight; }    public int fee() { return weight * 20; }}class ExpressParcel extends Parcel {    ExpressParcel(int weight) { super(weight); }    public int fee() { return super.fee() + 100; }}public class Main {    public static void main(String[] args) {        ExpressParcel parcel = new ExpressParcel(3);        System.out.println(parcel.weight());        System.out.println(parcel.fee());    }}
Java Reference