Java 知识测试 Java final keyword

Question 1

What is the use of final keyword in Java?

A. When a class is made final, a sublcass of it can not be created.

B. When a method is final, it can not be overridden.

C. When a variable is final, it can be assigned value only once.

D. All of the above

参考答案

```
D
```

Question 2

Output of follwoing Java program

class Main {
public static void main(String args[]) {
final int i;
i = 20;
System.out.println(i);
}
}

A. 20

B. Compiler Error

C. 0

D. Garbage value

参考答案

```
A
```

Question 3

class Main {
public static void main(String args[]) {
final int i;
i = 20;
i = 30;
System.out.println(i);
}
}

A. 30

B. Compiler Error

C. Garbage value

D. 0

参考答案

```
B
```

Question 4

class Base {
public final void show() {
System.out.println("Base::show() called");
}
} class Derived extends Base {
public void show() {
System.out.println("Derived::show() called");
}
} public class Main {
public static void main(String[] args) {
Base b = new Derived();
b.show();
}
}

A. Derived::show() called

B. Base::show() called

C. Compiler Error

D. Exception

参考答案

```
C
```

最新文章

  1. HTML无刷新提交表单
  2. [转]Linux下的lds链接脚本详解
  3. thinkphp介绍
  4. 浅谈MySQL索引背后的数据结构及算法(转载)
  5. 网络---中断套接字Socket
  6. Asp.Net操作FTP方法
  7. 【网络流24题】 No.12 软件补丁问题(最小转移代价 最短路)
  8. javascript学习笔记01--javascript的基本介绍
  9. OC语言(七)Block复习
  10. Axios源码深度剖析 - 替代$.ajax,成为xhr的新霸主
  11. [转] iphoneX、iphoneXS、iphoneXSMax、iphoneXR适配
  12. 简单使用普通用户启动tomcat
  13. Docker自制CentOS镜像
  14. delphi多语言
  15. 实现JTextfield 的右键 复制、剪切、粘贴功能。
  16. Docker swarm 使用服务编排部署lnmp
  17. C++11之auto和decltype
  18. eclipse 集成 github
  19. 《数据结构与算法JavaScript描述》中的一处错误
  20. FPGA学习(第8节)-Verilog设计电路的时序要点及时序仿真

热门文章

  1. Vant 实现 上拉加载更多
  2. JSON Web Token (JWT) - Weak secret
  3. 开源项目(5-2) yolo打包成库
  4. java 调度框架quartz
  5. html css div固定底部
  6. 《Elasticsearch实战》读书笔记
  7. 一篇文章把你带入到JavaScript中的闭包与高级函数
  8. UDS的使用
  9. 表格样式、表格css、
  10. java.lang.IllegalArgumentException: host parameter is null