Its return value must be the same or a subclass of that of the superclass method

computer science

Description

1 Exceptions and Method Overriding Recall that when a subclass method overrides a superclass method.

• It must have the same signature 

• Its return value must be the same or a subclass of that of the superclass method 

• Its access mode must be the same or wider than that of the superclass method


In other words, the overriding subclass method 

• Can remove an exception class declared in the superclass method header 

• Can replace an exception class by a subclass 

• But cannot add extra checked exception classes that are not subclasses of the exceptions declared in the superclass method 


Related Questions in computer science category