[Solved] how to override clear function in java


All you need to do to override a method is to write a method in your subclass with the same signature:

@Override
public void clear() { ... }

The @Override annotation isn’t required (unless you have non-default compiler settings) but is highly recommended to help catch programming errors. For instance, if the method is declared wrong (and therefore is not overriding an inherited method), the compiler will flag that as an error.

At some point in the method, you probably should call up to the parent class version of the method so it can do its own work. That’s done by the statement

super.clear();

0

solved how to override clear function in java