Language syntax
Java Method overriding and @Override
Defines an overriding instance method. @Override checks the intended relationship; normal runtime dispatch selects behavior for the actual object.
Formal Syntax & Structure
java syntaxjava
@Override public String message() { return "Delayed"; }Working Example
Example Snippetjava
class Notice { public String message() { return "General notice"; } public String label(int n) { return "Number " + n; }}class Delay extends Notice { @Override public String message() { return "Delayed"; } public String label(String s) { return "Text " + s; } public int minutes() { return 15; }}public class Main { public static void main(String[] args) { Notice notice = new Delay(); System.out.println(notice.message()); System.out.println(notice.label(4)); if (notice instanceof Delay delay) { System.out.println(delay.minutes()); System.out.println(delay.label("A")); } }}