8.4.5
Method Body
CLASSES
A method that overrides or hides another method ( 8.4.6), including methods
that implement
abstract
 methods defined in interfaces, may not be declared to
throw more checked exceptions than the overridden or hidden method.
More precisely, suppose that
B
 is a class or interface, and
A
 is a superclass or
superinterface of
B
, and a method declaration
n
 in
B
 overrides or hides a method
declaration
m
 in
A
. If
n
 has a
throws
 clause that mentions any checked exception
types, then
m
 must have a
throws
 clause, and for every checked exception type
listed in the
throws
 clause of
n
, that same exception class or one of its super 
classes must occur in the
throws
 clause of
m
; otherwise, a compile time error
occurs.
See  11 for more information about exceptions and a large example.
8.4.5   Method Body
A
method body
 is either a block of code that implements the method or simply a
semicolon, indicating the lack of an implementation. The body of a method must
be a semicolon if and only if the method is either
abstract
 ( 8.4.3.1) or
native
( 8.4.3.4).
MethodBody:
Block
;
A compile time error occurs if a method declaration is either
abstract
 or
native
 and has a block for its body. A compile time error occurs if a method dec 
laration is neither
abstract
 nor
native
 and has a semicolon for its body.
If an implementation is to be provided for a method but the implementation
requires no executable code, the method body should be written as a block that
contains no statements:  
{ }
 .
If a method is declared
void
, then its body must not contain any
return
statement ( 14.15) that has an
Expression
.
If a method is declared to have a return type, then every
return
 statement
( 14.15) in its body must have an
Expression
. A compile time error occurs if the
body of the method can complete normally ( 14.1). In other words, a method with
a return type must return only by using a return statement that provides a value
return; it is not allowed to  drop off the end of its body. 
Note that it is possible for a method to have a declared return type and yet
contain no return statements. Here is one example:
164






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