CLASSES
Inheritance, Overriding, and Hiding
8.4.6
class DizzyDean {
int pitch() { throw new RuntimeException("90 mph?!"); }
}
8.4.6   Inheritance, Overriding, and Hiding
A class
inherits
 from its direct superclass and direct superinterfaces all the meth 
ods (whether
abstract
 or not) of the superclass and superinterfaces that are
accessible to code in the class and are neither overridden ( 8.4.6.1) nor hidden
( 8.4.6.2) by a declaration in the class.
8.4.6.1
Overriding (By Instance Methods)
If a class declares an instance method, then the declaration of that method is said
to
override
 any and all methods with the same signature in the superclasses and
superinterfaces of the class that would otherwise be accessible to code in the class.
Moreover, if the method declared in the class is not
abstract
, then the declara 
tion of that method is said to
implement
 any and all declarations of
abstract
methods with the same signature in the superclasses and superinterfaces of the
class that would otherwise be accessible to code in the class.
A compile time error occurs if an instance method overrides a
static
method. In this respect, overriding of methods differs from hiding of fields ( 8.3),
for it is permissible for an instance variable to hide a
static
 variable.
An overridden method can be accessed by using a method invocation expres 
sion ( 15.11) that contains the keyword
super
. Note that a qualified name or a
cast to a superclass type is not effective in attempting to access an overridden
method; in this respect, overriding of methods differs from hiding of fields. See
 15.11.4.10 for discussion and examples of this point.
8.4.6.2
Hiding (By Class Methods)
If a class declares a
static
 method, then the declaration of that method is said to
hide
 any and all methods with the same signature in the superclasses and super 
interfaces of the class that would otherwise be accessible to code in the class. A
compile time error occurs if a
static
 method hides an instance method. In this
respect, hiding of methods differs from hiding of fields ( 8.3), for it is permissible
for a
static
 variable to hide an instance variable.
A hidden method can be accessed by using a qualified name or by using a
method invocation expression ( 15.11) that contains the keyword
super
 or a cast
to a superclass type. In this respect, hiding of methods is similar to hiding of
fields.
165






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