为什么 Java 中的类有时会声明为 final?
如果一个类声明为 final,则不能继承它。如果你尝试,它会在编译时报错,如 -
示例
final class Super {
private int data = 30;
}
public class Sub extends Sub {
public static void main(String args[]){
}
}
输出
Exception in thread "main" java.lang.Error: Unresolved compilation problem: at Sub.main(Sub.java:7)
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP