笔试题 Overriding in Java

Question 1 以下程序的输出结果为( )。

class Derived {
protected final void getDetails() {
System.out.println("Derived class");
}
} public class Test extends Derived {
protected final void getDetails() {
System.out.println("Test class");
} public static void main(String[] args) {
Derived obj = new Derived();
obj.getDetails();
}
}

a) Derived class

b) Test class

c) Runtime error

d) Compilation error

参考答案

```
d
```

Question 2 以下程序的输出结果为( )。

class Derived {
public void getDetails(String temp) {
System.out.println("Derived class " + temp);
}
} public class Test extends Derived {
public int getDetails(String temp) {
System.out.println("Test class " + temp);
return 0;
} public static void main(String[] args) {
Test obj = new Test();
obj.getDetails("GFG");
}
}

a) Derived class GFG

b) Test class GFG

c) Compilation error

d) Runtime error

参考答案

```
c
```

Question 3 以下程序的输出结果为( )。

class Derived {
public void getDetails() {
System.out.println("Derived class");
}
} public class Test extends Derived {
protected void getDetails() {
System.out.println("Test class");
} public static void main(String[] args) {
Derived obj = new Test(); // line xyz
obj.getDetails();
}
}

a) Test class

b) Compilation error due to line xyz

c) Derived class

d) Compilation error due to access modifier

参考答案

```
d
```

Question 4 以下程序的输出结果为( )。

import java.io.IOException;

class Derived {
public void getDetails() throws IOException { // line 23
System.out.println("Derived class");
}
} public class Test extends Derived {
public void getDetails() throws Exception { // line 24
System.out.println("Test class");
} public static void main(String[] args) throws IOException { // line 25
Derived obj = new Test();
obj.getDetails();
}
}

a) Compilation error due to line 23

b) Compilation error due to line 24

c) Compilation error due to line 25

d) All the above

参考答案

```
b
```

Question 5 以下程序的输出结果为( )。

class Derived {
public void getDetails() {
System.out.printf("Derived class ");
}
} public class Test extends Derived {
public void getDetails() {
System.out.printf("Test class ");
super.getDetails();
} public static void main(String[] args) {
Derived obj = new Test();
obj.getDetails();
}
}

a) Test class Derived class

b) Derived class Test class

c) Compilation error

d) Runtime error

参考答案

```
a
```

参考链接

最新文章

  1. java解析XML(转载)
  2. 自己写的 限制文本框TEdit中只能输入数字
  3. bootstrap的popover插件在focus模式时在Safari浏览器无法使用的bug解决方案
  4. three.js入门2
  5. 生成月初月末便于拼接sql
  6. Android测试框架初步
  7. [Windows] Visual Studio 2010 快捷键大全
  8. 安装numpy/scipy/scikit-learn的方法
  9. Codeforces 350B Resort
  10. Android 常用网站
  11. LeeCode(Database)-Customers Who Never Order
  12. dfs+dp思想的结合------hdu1078
  13. synchronized关键字简介 多线程中篇(十一)
  14. zipline-- 开发指南
  15. Python 中 __all__ 的作用(转)
  16. 【做题】HDU6331 Walking Plan——矩阵&分块
  17. IDEA如何把写好的java文件/项目打包成一个jar的文件
  18. HNOI/AHOI2018题解
  19. redis持久化的两种方式
  20. [DNS]部署局域网DNS服务器

热门文章

  1. Linux/Windows 配置config 使用ssh连接
  2. Cortex Architecture
  3. A_G_C_007
  4. python格式化输出之format用法
  5. 第09组 Alpha冲刺(1/6)
  6. mariadb新安装解决远程访问以及root登录
  7. Docker容器CPU、memory资源限制
  8. 【面向对象】第四单元总结——UML
  9. 咏南跨平台中间件REST API
  10. 破解magento加密的密码算法