8.4.6
Inheritance, Overriding, and Hiding
CLASSES
8.4.6.3
Requirements in Overriding and Hiding
If a method declaration overrides or hides the declaration of another method, then
a compile time error occurs if they have different return types or if one has a
return type and the other is
void
. Moreover, a method declaration must not have a
throws
 clause that conflicts ( 8.4.4) with that of any method that it overrides or
hides; otherwise, a compile time error occurs. In these respects, overriding of
methods differs from hiding of fields ( 8.3), for it is permissible for a field to hide
a field of another type.
The access modifier ( 6.6) of an overriding or hiding method must provide at
least as much access as the overridden or hidden method, or a compile time error
occurs. In more detail:
If the overridden or hidden method is
public
, then the overriding or hiding
method must be
public
; otherwise, a compile time error occurs.
If the overridden or hidden method is
protected
, then the overriding or hid 
ing method must be
protected
 or
public
; otherwise, a compile time error
occurs.
If the overridden or hidden method has default (package) access, then the
overriding or hiding method must not be
private
; otherwise, a compile time
error occurs.
Note that a
private
 method is never accessible to subclasses and so cannot be
hidden or overridden in the technical sense of those terms. This means that a sub 
class can declare a method with the same signature as a
private
 method in one of
its superclasses, and there is no requirement that the return type or
throws
 clause
of such a method bear any relationship to those of the
private
 method in the
superclass.
8.4.6.4
Inheriting Methods with the Same Signature
It is possible for a class to inherit more than one method with the same signature
( 8.4.6.4). Such a situation does not in itself cause a compile time error. There are
then two possible cases:
If one of the inherited methods is not
abstract
, then there are two subcases:
N
If the method that is not
abstract
 is
static
, a compile time error occurs.
N
Otherwise, the method that is not
abstract
 is considered to override, and
therefore to implement, all the other methods on behalf of the class that
inherits it. A compile time error occurs if, comparing the method that is not
abstract
 with each of the other of the inherited methods, for any such pair,
166






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved