北京东方国信JAVA面试题-答案
更新时间:2023-10-17 13:55:02 阅读量: 综合文库 文档下载
- 北京东方国信怎么样推荐度:
- 相关推荐
Part Ⅰ(每题1分)
1) Which of the following lines will compile without warning or error? Select all
valid answers. a e
a) float f=0;
b) char c=\ c) byte b=157; d) boolean f=null; e) int i=10;
2) What are the valid types for the given variable i ? c
public class Base{
private void test() {
// i = 1;
switch (i) { } }
static public void main(String[] a) {
new Base().test(); } }
Select most appropriate answer. a) char, int
b) boolean, byte, char, short, int c) byte, char, short, int
d) byte, char, short, int, long e) Only int
3) What is the correct way of declarating main() so that the progarm can be
compiled and executed using this entry point. abcf
a) static public void main(String[] args) b) static public void main(String a[]) c) public static void main(String[] a) d) static void public main(String[] a) e) public void main(String[] a)
f) static public void main(char arg[][])
1
4) What will be output if the program is executed as below
java -DOne -DTwo -DThree Sample
public class Sample{
public static void main(String argv[]) {
System.out.println(argv[2]) } }
Select most appropriate answer. b a) One b) Two c) Three
d) Exception raised: \ e) None
Part Ⅱ(每题1分)
5) Abstract method cannot be static. True or False ? true
a) True b) False
6) What will be the output when you compile and execute the following
program. d
//////////////////////////////////////////// class Base {
void test() {
System.out.println(\} }
//////////////////////////////////////////// public class Child extends Base {
void test() {
System.out.println(\}
static public void main(String[] a) {
Child anObj = new Child(); Base baseObj = (Base)anObj;
2
//Base b=new Child(); //b.test();
baseObj.test(); }
}
Select most appropriate answer. a) Child.test()
Base.test() b) Base.test()
Child.test() c) Base.test() d) Child.test()
7) What will be the output when you compile and execute the following
program. C
//////////////////////////////////////////// class Base {
static void test() {
System.out.println(\} }
//////////////////////////////////////////// public class Child extends Base {
void test() {
System.out.println(\Base.test(); //Call the parent method }
static public void main(String[] a) {
new Child().test(); } }
Select most appropriate answer. a) Child.test()
Base.test() b) Child.test()
Child.test()
c) Compilation error. Cannot override a static method by an instance method d) Runtime error. Cannot override a static method by an instance method
3
8) What will be the output when you compile and execute the following
program.
Exception is the base class for all the Exception classes. //////////////////////////////////////////// import java.io.*;
class Base {
void test() throws IOException {
System.out.println(\String a = null;
//Complex logic goes here if(a == null)
throw new IOException(\} }
//////////////////////////////////////////// public class Child extends Base {
protected void test() throws Exception {
System.out.println(\throw new Exception(\}
static public void main(String[] a) {
try {
new Child().test(); }
catch(Exception e) { } } }
Select most appropriate answer. b
a) Child.test()
Base.test()
b) Compilation Error: The method void test() declared in class Child cannot override the method
of the same signature declared in class Base. Their throws clauses are incompatible.
c) Compilation Error: The method void test() declared in class Child cannot override the method
of the same signature declared in class Base. The access modifier is made more restrictive. d) Runtime error. Cannot make the access modifier more restrictive for test()
4
Part Ⅲ(每题1分)
9) What will be the output when you compile and execute the following
program. b
public class Base{
private void test() {
System.out.println(6 + 6 + \ }
static public void main(String[] a) {
new Base().test(); } }
Select most appropriate answer. a) 66(Result) b) 12(Result)
c) Runtime Error.Incompatible type for +. Can't convert an int to a string. d) Compilation Error.Incompatible type for +. Can't add a string to an int.
10) What will be the output when you compile and execute the following
program. The symbol ’ ?’ means space. e
1:public class Base{ 2:
3: private void test() { 4: 5:
String aStr = \?One?\
6: String bStr = aStr; 7: aStr.toUpperCase(); 8: aStr.trim(); 9: System.out.println(\7: } 8:
9: static public void main(String[] a) { 10: new Base().test(); 11: } 12: }
Select most appropriate answer.
5
a) [ONE,?One?] b) [?One?,One] c) [ONE,One] d) [ONE,ONE] e) [?One?,?One?]
11) What will be the output when you compile and execute the following
program. d
public class Base {
void test() {
String aStr = \
System.out.println(aStr.substring(3,7)); }
static public void main(String[] a) {
new Base().test(); } }
Select most appropriate answer. a) Strin b) String c) trin d) Stri
12) What can contain objects that have a unique key field of String type, if it is
required to retrieve the objects using that key field as an index? a
a) Map b) Set c) List
d) Collection e) Enumeration
Part Ⅳ(每题1分)
13) At what point are the objects i2, i3 and i4 available for garbage collection.
01:public class Base {
6
02: Base i;
03: public static void main(String [] args) { 04: Base i2 = new Base(); 05: Base i3 = new Base(); 06: Base i4 = new Base(); 07: 08: i2.i = i3; // i2 refers to i3 09: i3.i = i4; // i3 refers to i4 10: i4.i = i2; // i4 refers to i2 11: 12: i2 = null; 13: i3 = null; 14: i4 = null; 15: // do complicated, memory intensive stuff 16: } 17:}
Select most appropriate answer d a) After line 6 b) After line 9 c) After line 10 d) After line 14 e) After line 16
System.gc()
Runtime.getRuntime().gc()
Java的垃圾回收机制是Java虚拟机提供的能力,用于在空闲时间以不定时的方式动态回收无任何引用的对象占据的内存空间。
14) A try statement must always associate with a f
a) catch
b) None of these c) throws d) throw e) finally
f) catch, finally or both
15) Which of the following are correct way of throwing an exception inside a
method?
Select all valid answers b a) new throw Exception(\
7
b) throw new Exception(\c) throws IOException() d) throws IOException e) catch(Exception e) { }
16) The method test() throws MalformedURLException and EOFException.
IOException is the parent class of MalformedURLException and EOFException. What changes will make the following code to compile without any errors.
import java.io.*; import java.net.*;
public class Base{
private void test() { String a = null; String b = \
// Complex processing if(a==null)
throw new MalformedURLException(\
if(b ==null)
throw new EOFException(\
// Complex processing } }
Select all valid answers a d a) private void test() throws IOException
b) private void test() throws EOFException, throws MalformedURLException c) private void test() throws EOFException throws MalformedURLException d) private void test() throws EOFException, MalformedURLException e) private void test() throws EOFException MalformedURLException
Part Ⅴ(每题1分)
17) Which class or interface defines the wait(), notify(), and notifyAll() methods?
a
a) Object
8
b) Thread c) Runnable d) Class
18) Given the following,
1. class MyThread extends Thread { 2.
3. public static void main(String [] args) { 4. MyThread t = new MyThread(); 5. t.run(); 6. } 7.
8. public void run() { 9. for(int i=1;i<3;++i) {
10. System.out.print(i + \11. } 12. } 13. }
what is the result? c
a) This code will not compile due to line 4. b) This code will not compile due to line 5. c) 1..2.. d) 1..2..3..
e) An exception is thrown at runtime.
19) Given the following,
class MyThread extends Thread { MyThread() {
System.out.print(\}
public void run() {
System.out.print(\}
public void run(String s) { System.out.println(\} }
public class TestThreads {
public static void main (String [] args) { Thread t = new MyThread() { public void run() {
System.out.println(\}
9
};
t.start(); }
}
what is the result? b a) foo
b) MyThread foo c) MyThread bar d) foo bar e) foo bar baz f) bar foo
g) Compilation fails.
20) Given the following,
1. public class Test {
2. public static void main (String [] args) { 3. final Foo f = new Foo();
4. Thread t = new Thread(new Runnable() { 5. public void run() { 6. f.doStuff(); 7. } 8. });
9. Thread g = new Thread() { 10. public void run() { 11. f.doStuff(); 12. } 13. };
14. t.start(); 15. g.start(); 16. } 17. }
1. class Foo { 2. int x = 5;
3. public void doStuff() { 4. if (x < 10) {
5. // nothing to do 6. try { 7. wait();
8. } catch(InterruptedException ex) { } 9. } else {
10. System.out.println(\11. if (x >= 10) { 12. notify(); 13. }
10
正在阅读:
北京东方国信JAVA面试题-答案10-17
关于寒假的作文:寒假里一次有趣的活动或一件难忘的事02-04
高中数学 解三角形苏教版必修505-27
基于人机界面的物料自动分拣装置的PLC控制系统设计报告 - 图文10-11
党员入党程序02-06
机械制造基础03-24
小学记叙文写作大全 - 图文02-03
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 国信
- 北京
- 试题
- 答案
- 东方
- JAVA
- 5-1,泸定县新城建设一期工程土地整理场平施工方案
- 六年级语文综合能力竞赛试题
- 食品安全教育讲话稿
- 高处安装、维护、拆除作业考试1
- 13(A)型车钩分离故障调查竞赛要求及标准 - 图文
- 木材科学与技术研究进展
- 秘书学原理
- 文言文教学模式结题报告
- 2017年智能制造装备企业组织结构、商业模式、行业现状
- “新常态”课堂:守正 出新
- 教科版小学三年级科学下册全册教案11
- 普通心理学 - 图文
- 广州市高校新校区房屋建筑施工组织设计A、B方案
- 直线裁剪算法研究(Cohen-Sutherland算法和Liang-Barsky算法)
- 人教版七年级地理上册1.1《地球和地球仪》教学设计
- 基于UML的物流存储管理系统分析与设计
- 小学英语论文
- 5524消毒供应室工作制度、职责、操作流程
- 化学竞赛模拟试题1
- 转向架综述 - 图文