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