abstract类的定义及final的用法!
来源:互联网 发布:bnn网络 编辑:程序博客网 时间:2024/04/28 01:43
abstract
以下三种情况要申明abstrat
- C explicitly contains a declaration of an
abstract
method.
类C中的确包含一个已申明为虚函数的函数。
- Any of C's superclasses declares an
abstract
method that has not been implemented in C or any of its superclasses.
类C的任何一个超类定义了一个虚函数且这个虚函数没有被类C和其任何一个超类所具体化。
- 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:
a classabstract 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() { } }
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:
would result in a compile-time error; the classPoint p = new Point();
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.
final
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
——在自java文档http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#35962
- abstract类的定义及final的用法!
- final与abstract的用法
- Java的abstract,static ,final关键字的用法
- final/abstract/static类的规则对比
- java中的final关键字、抽象类及接口的定义
- Java基础--类的定义及用法
- 抽象类和接口的区别,static,final,abstract等
- abstract的一些用法
- Intent的定义及用法
- Java 里的 abstract 和 final 关键字
- final、static、abstract修饰符的作用
- 黑马程序员----java中static,final,abstract的用法和区别
- final 、 abstract类
- final的用法
- 关于Final的用法
- final的用法
- final的用法
- 关键字final的用法!!
- dynamic programming
- 和牛人聊天以后。。。
- 葡荷大战在即,Scolari开始降温去火
- 善用"静态新闻"里的Javascript,还是可以个性化自己的Blog的嘛。
- 用C++实现委托
- abstract类的定义及final的用法!
- 人生感悟第一篇章
- ODBC的多线程应用
- 全文检索
- 一个对c++的批评
- c++的streaming
- packet类的一些思路
- 播放器的。。。使用
- 配置adhoc