Java Reference
In-Depth Information
3.7.4
Overriding methods in your superclass
You can override any of your parent
class methods by using the Code |
Override Methods command ( Ctrl+
O ). This command presents you with a
list of methods you can override,
grouped by the classes that first
defined the method. Only methods
that have not already been overridden,
and that are accessible from your sub-
class, are shown. An example with sev-
eral ancestors is shown in figure 3.21.
Select the method (or methods) you
wish to override, and IDEA will create
the methods for you. By default, the
body of the method calls the super-
class's method, resulting in no change
in behavior. You'll have to add a useful
body to the method yourself, of course.
If you enable the Copy JavaDoc
option, then the JavaDoc from the
overridden methods (if any) is copied
into your source file. Otherwise, no
JavaDoc will be generated.
3.7.5
Implementing methods of
an interface
The Code | Implement Methods com-
mand ( Ctrl+I ) is very similar to the
Override Methods command. When
it's executed, you're presented with a
list of methods that your class needs to
implement, because either it has declared itself as implementing a particular
interface or it's extending a class with abstract methods.
In the example shown in figure 3.22, we've called the command from a class
that is declared as implementing the MouseListener and MouseMotionListener
interfaces, and we're required to implement seven methods. Select one or more
Figure 3.21 There's no need to fear specifying
the wrong method signature when you're trying
to override a method. Using the Override
Methods command shows you a list of every
inherited method and will insert any subset of
them directly into your current class.
 
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search