Overriding Methods of a Superclass
In this section:
Overview
You can override any method of a parent class, using the code generation facility. IntelliJ IDEA creates a stub that contains a call to the method of the superclass, leaving the developer with the task of providing some meaningful source code.
Overriding methods
To override methods, follow these steps:
- With the class in question having the focus, invoke the command in one of the following ways:
- Select methods that can be overridden from the Select methods to override
dialog box.
The list of methods does not include the methods that are already overridden, or cannot be accessed from
the current subclass.
- Select one or more methods to override.
- If necessary, select the following options:
- Having generated the overriding method, create the required source code.
Note the
icon that marks the overriding method in the left gutter. Use this icon to view the name of the base class, and navigate to the overridden method.
Changing method body
File template responsible for overriding a method (Overridden method body) accepts
predefined template variables from "File Header" (
),
e.g. ${USER}
, ${DATE}
, etc.
For example, consider the following file template:
#if ( $RETURN_TYPE != "void" )return $DEFAULT_RETURN_VALUE;#end // TODO ($USER, $DATE):To change the method body, use Settings - Editor - File and Code Templates.
Provided that an overridden class contains two methods, this template expands into the following code:
public void breathe() {
// TODO (wombat, 9/21/12): To change the method body, use Settings - Editor - File and Code Templates.
}
public void eat() {
// TODO (wombat, 9/21/12): To change the method body, use Settings - Editor - File and Code Templates.
}
See Also
Reference:
Last modified: 13 July 2016