CLASSES
Class Modifiers
8.1.2
8.1.2.1
abstract
Classes
An
abstract
 class is a class that is incomplete, or to be considered incomplete.
Only
abstract
 classes may have
abstract
 methods ( 8.4.3.1,  9.4), that is,
methods that are declared but not yet implemented. If a class that is not
abstract
contains an
abstract
 method, then a compile time error occurs. A class has
abstract
 methods if any of the following is true:
It explicitly contains a declaration of an
abstract
 method ( 8.4.3).
It inherits an
abstract
 method from its direct superclass ( 8.1.3).
A direct superinterface ( 8.1.4) of the class declares or inherits a method
(which is therefore necessarily
abstract
) and the class neither declares nor
inherits a method that implements it.
In the example:
abstract class Point {
int x = 1, y = 1;
void move(int dx, int dy) {
x += dx;
y += dy;
alert();
}
abstract void alert();
}
abstract class ColoredPoint extends Point {
int color;
}
class SimplePoint extends Point {
void alert() { }
}
a class
Point
 is declared that must be declared
abstract
, because it contains a
declaration of an
abstract
 method named
alert
. The subclass of
Point
 named
ColoredPoint
 inherits the
abstract
 method
alert
, so it must also be declared
abstract
. On the other hand, the subclass of
Point
 named
SimplePoint
 pro 
vides an implementation of
alert
, so it need not be
abstract
.
A compile time error occurs if an attempt is made to create an instance of an
abstract
 class using a class instance creation expression ( 15.8). An attempt to
instantiate an
abstract
 class using the
newInstance
 method of class
Class
( 20.3.6) will cause an
InstantiationException
 ( 11.5.1) to be thrown. Thus,
continuing the example just shown, the statement:
Point p = new Point();
131






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