img zhanghaolpc


发表于2004/6/30 21:31:00  1957人阅读

分类: java



  • C explicitly contains a declaration of an abstract method.


  • Any of C's superclasses declares an abstract method that has not been implemented  in C or any of its superclasses.


  • A direct superinterface  of  C declares or inherits a method (which is therefore necessarily abstract) and C neither declares nor inherits a method that implements it.

      类C的直接超接口或继承的函数(类C当然应该是abstract) 且类C既没定义也没继承并使之具体化。  如下例中的  ColoredPoint   


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 provides 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 .

Thus, continuing the example just shown, the statement:

 Point p = new Point(); 
would result in a compile-time error; the class Point cannot be instantiated because it is abstract. However, a Point variable could correctly be initialized with a reference to any subclass of Point, and the class SimplePoint is not abstract, so the statement:

 Point p = new SimplePoint(); 

would be correct.


A class can be declared final if its definition is complete and no subclasses are desired or required. A compile-time error occurs if the name of a final class appears in the extends clause  of another class declaration; this implies that a final class cannot have any subclasses. A compile-time error occurs if a class is declared both final and abstract, because the implementation of such a class could never be completed .

Because a final class never has any subclasses, the methods of a final class are never overridden


0 0



取 消