益模软件Java笔试题


Posted in 面试题 onMarch 27, 2012
java笔试题目
QUESTION NO: 1
1. public class Test {
2. public static void main(String args[]) {
3. class Foo {
4. public int i = 3;
5. }
6. Object o = (Object)new Foo();
7. Foo foo = (Foo)o;
8. System.out.println(“i = “ + foo.i);
9. }
10. }
What is the result?
A. i = 3
B. Compilation fails.
C. A ClassCastException is thrown at line 6.
D. A ClassCastException is thrown at line 7.

QUESTION NO: 2

11. int i =1,j =10;
12. do {
13. if(i++> –j) {
14. continue;
15. }
16. } while (i 17. System.out.println(“i = “ +i+ “and j = “+j);
What is the result?
A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 5
D. i = 5 and j = 6
E. i = 6 and j = 6

QUESTION NO: 3
Given:
1. class Test {
2. private Demo d;
3. void start() {
4. d = new Demo();
5. this.takeDemo(d);
6. }
7.
8. void takeDemo(Demo demo) {
9. demo = null;
10. demo = new Demo();
11. }
12. }
When is the Demo object, created on line 3, eligible for garbage collection?
A. After line 5.
B. After line 9.
C. After the start() method completes.
D. When the takeDemo() method completes.
E. When the instance running this code is made eligible for garbage collection.

QUESTION NO: 4
Given:
1. interface Animal {
2. void soundOff();
3. }
4.
5. class Elephant implements Animal {
6. public void soundOff() {
7. System.out.println(“Trumpet”);
8. }
9. }
10.
11. class Lion implements Animal {
12. public void soundOff() {
13. System.out.println(“Roar”);
14. }
15. }
16.
17. class Alpha1 {
18. static Animal get( String choice ) {
19. if ( choice.equalsIgnoreCase( “meat eater” )) {
20. return new Lion();
21. } else {
22. return new Elephant();
23. }
24. }
25. }
Which compiles?
A. new Animal().soundOff();
B. Elephant e = new Alpha1();
C. Lion 1 = Alpha.get(“meat eater”);
D. new Alpha1().get(“veggie”).soundOff();

QUESTION NO: 5
Given:
1. class A {
2. A() { }
3. }
4.
5. class B extends A {
6. }
Which two statements are true? (Choose two)
A. Class B’s constructor is public.
B. Class B’s constructor has no arguments.
C. Class B’s constructor includes a call to this().
D. Class B’s constructor includes a call to super().

QUESTION NO: 6
Given:
11. int i = 1,j = 10;
12. do {
13. if(i>j) {
14. break;
15. }
16. j–;
17. } while (++i 18. System.out.println(“i =” +i+” and j = “+j);
What is the result?
A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 4
D. i = 5 and j = 6
E. i = 6 and j = 6

QUESTION NO: 7
1. class Super {
2. public float getNum() { return 3.0f; }
3. }
4.
5. public class Sub extends Super {.
7. }
Which method, placed at line6, causes compilation to fail?
A. public void getNum() { }
B. public void getNum(double d) { }
C. public float getNum() { return 4.0f; }
D. public double getNum(float d) { return 4.0d; }

QUESTION NO: 8
Which statement is true?
A. catch(X x) can catch subclasses of X.
B. The Error class is a RuntimeException.
C. Any statement that can throw an Error must be enclosed in a try block.
D. Any statement that can throw an Exception must be enclosed in a try block.
E. Any statement that can throw a RuntimeException must be enclosed in a try
block.

QUESTION NO: 9
Which three form part of correct array declarations? (Choose three)
A. public int a []
B. static int [] a
C. public [] int a
D. private int a [3]
E. private int [3] a []
F. public final int [] a

QUESTION NO: 10

1. public class Foo {
2. public static void main(String[] args) {
3. try {
4. return;
5. } finally {
6. System.out.println( “Finally” );
7. }
8. }
9. }
What is the result?
A. Finally
B. Compilation fails.
C. The code runs with no output.
D. An exception is thrown at runtime.

QUESTION NO: 11
Given:
ClassOne.java:
1. package com.abe.pkg1;
2. public class ClassOne {
3. private char var = ‘a’;
4. char getVar() { return var; }
5. }
ClassTest.java:
1. package com.abe.pkg2;
2. import com.abc.pkg1.ClassOne;
3. public class ClassTest extends ClassOne {
4. public static void main(String[] args) {
5. char a = new ClassOne().getVar();
6. char b = new ClassTest().getVar();
7. }
8. }
What is the result?
A. Compilation fails.
B. Compilation succeeds and no exceptions are thrown.
C. An exception is thrown at line 5 in ClassTest.java.
D. An exception is thrown at line 6 in ClassTest.java.

QUESTION NO: 12
Given:
1. class TestA {
2. TestB b;
3. TestA() {
4. b = new TestB(this);
5. }
6. }
7. class TestB {
8. TestA a;
9. TestB(TestA a) {
10. this.a = a;
11. }
12. }
13. class TestAll {
14. public static void main (String args[]) {
15. new TestAll().makeThings();
16. // …code continues on
17. }
18. void makeThings() {
19. TestA test = new TestA();
20. }
21. }
Which two statements are true after line 15, before main completes? (Choose two)
A. Line 15 causes a stack overflow.
B. An exception is thrown at runtime.
C. The object referenced by a is eligible for garbage collection.
D. The object referenced by b is eligible for garbage collection.
E. The object referenced by a is not eligible for garbage collection.
F. The object referenced by b is not eligible for garbage collection.

QUESTION NO: 13
Given:
1. public class ReturnIt {
2. return Type methodA(byte x, double y) {
3. return (long)x / y * 2;
4. }
5. }
What is the narrowest valid returnType for methodA in line2?
A. int
B. byte
C. long
D. short
E. float
F. double

QUESTION NO:14
Given:
1. public class OuterClass {
2. private double d1 = 1.0;
3. // insert code here
4. }
Which two are valid if inserted at line 3? (Choose two)
A. static class InnerOne {
public double methoda() { return d1; }
}
B. static class InnerOne {
static double methoda() { return d1; }
}
C. private class InnerOne {
public double methoda() { return d1; }
}
D. protected class InnerOne {
static double methoda() { return d1; }
}
E. public abstract class InnerOne {
public abstract double methoda();
}

QUESTION NO: 15
Given:
1. public abstract class Test {
2. public abstract void methodA();
3.
4. public abstract void methodB()
5. {
6. System.out.println(“Hello”);
7. }
8. }
Which two changes, independently applied, allow this code to compile? (Choose two)
A. Add a method body to methodA.
B. Replace lines 5 – 7 with a semicolon (“;”).
C. Remove the abstract qualifier from the declaration of Test.
D. Remove the abstract qualifier from the declaration of methodA.
E. Remove the abstract qualifier from the declaration of methodB.

QUESTION NO: 16
Given:
1. interface Beta {}
2.
3. class Alpha implements Beta {
4. String testIt() {
5. return “Tested”;
6. }
7. }
8.
9. public class Main1 {
10. static Beta getIt() {
11. return new Alpha();
12. }
13. public static void main( String[] args ) {
14. Beta b = getIt();
15. System.out.println( b.testIt() );
16. }
17. }
What is the result?
A. Tested
B. Compilation fails.
C. The code runs with no output.
D. An exception is thrown at runtime.

QUESTION NO: 17
Given:
1. public class Exception Test {
2. class TestException extends Exception {}
3. public void runTest() throws TestException {}
4. public void test() /* Point X */ {
5. runTest();
6. }
7. }
At Point X on line 4, which code is necessary to make the code compile?
A. No code is necessary.
B. throws Exception
C. catch ( Exception e )
D. throws RuntimeException
E. catch ( TestException e)

QUESTION NO: 18
Given that b and c refer to instances of wrapper classes, which two statements are
true? (Choose two)
A. b.equals(b) returns true.
B. b.equals(c) returns the same result as b == c.
C. b.eqials(c) can return false even if c.equals(b) returns true.
D. b.equals(c) throws an exception if b and c are different wrapper types.
E. b.equals(c) returns false if the type of wrapper objects being compared are
different.

QUESTION NO: 19
Given:
11. try {
12. if ((new Object))(.equals((new Object()))) {
13. System.out.println(“equal”);
14. )else{
15. System.out.println(“not equal”);
16. }
17. }catch (Exception e) {
18. System.out.println(“exception”);
19. }
What is the result?
A. equal
B. not equal
C. exception
D. Compilation fails.

QUESTION NO: 20
Given:
1. class BaseClass {
2. private float x = 1.of;
3. protected float getVar() { return x; }
4. }
5. class SubClass extends BaseClass {
6. private float x = 2.Of;
7. // insert code here
8. }
Which two are valid examples of method overriding when inserted at line 7? (Choose
two)
A. float getVar() { return x; }
B. public float getVar() { return x; }
C. public double getVar() { return x; }
D. protected float getVar() { return x; }
E. public float getVar(float f) { return f; }

QUESTION NO: 21
Given:
1. public class SyncTest {
2. private int x;
3. private int y;
4. private synchronized void setX( int i ) { x = i; }
5. private synchronized void setY( int i ) { y = i; }
6. public void setXY( int i ) { setX(i); setY(i); }
7. public synchronized boolean check() { return x != y; }
8. }
Under which condition will check return true when called from a different class?
A. check can never return true.
B. check can return true when setXY is called by multiple threads.
C. check can return true when multiple threads call setX and setY separately.
D. check can return true only if SyncTest is changed to allow x and y to be set
separately.

QUESTION NO: 22
Given:
1. public class X implements Runnable {
2. private int x;
3. private int y;
4.
5. public static void main(String [] args) {
6. X that = new X();
7. (new Thread( that )).start();
8. (new Thread( that )).start();
9. }
10.
11. public void run() {
12. for (;;) {
13. synchronized (this) {
14. x++;
15. y++;
16. }
17.
System.out.println(Thread.currentThread().getName() +
18. “x = “ + x + “, y = “ +
y);
19. }
20. }
21. }
What is the result?
A. Compilation fails.
B. The program prints pairs of values for x and y that might not always be the same on
the same line (for example, “x = 2, y = 1”).
C. The program prints pairs of values for x and y that are always the same on the same
line (for example, “x = 1, y = 1”).
In addition, each value appears only once (for example, “x = 1, y = 1” followed
by “x = 2, y = 2”).
The thread name at the start of the line shows that both threads are executing
concurrently.
D. The program prints pairs of values for x and y that are always the same on the same
line (for example, “x = 1, y = 1”).
In addition, each value appears only once (for example, “x = 1, y = 1” followed
by “x = 2, y = 2”).
The thread name at the start of the line shows that only a single thread is actually
executing.

QUESTION NO: 23
Given:
1. // Point X
2. public class foo {
3. public static void main(String[] args) throws Exception {
4. jave.io.PrintWriter out = new jave.io.PrintWriter(
5. new jave.io.OutputStreamWriter(System.out), true);
6. out.println(“Hello”);
7. }
8. }
Which statement at Point X on line 1 is required to allow this code to compile?
A. No statement is required.
B. import jave.io.*;
C. include java.io.*;
D. import jave.io.PrintWriter;
E. include java.io.PrintWriter;

QUESTION NO: 24
Which two are valid declarations of a float? (Choose two)
A. float f = 1F;
B. float f = 1.0.;
C. float f = ‘1’;
D. float f = “1”;
E. float f = 1.0d;

QUESTION NO: 25
What is the numerical range of a char?
A. 0 … 32767
B. 0 … 65535
310 – 035
Leading the way in IT testing and certification tools, www.testking.com
-65 -
C. –256 … 255
D. –32768 … 32767
E. Range is platform dependent.

QUESTION NO: 26
Which code determines the int value foo closest to, but not greater than, a double value
bar?
A. Int foo = (int) Math.max(bar);
B. Int foo = (int) Math.min(bar);
C. Int foo = (int) Math.abs(bar);
D. Int foo = (int) Math.ceil(bar);
E. Int foo = (int) Math.floor(bar);
F. Int foo = (int) Math.round(bar);

QUESTION NO: 27
Exhibit:
1. public class Mycircle {
2. public double radius;
3. public double diameter;
4.
5. public void setRadius(double radius)
6. this.radius = radius;
7. this.diameter= radius * 2;
8. }
9.
10. public double getRadius() {
11. return radius;
12. }
13. }
Which statement is true?
A. The Mycircle class is fully encapsulated.
B. The diameter of a given MyCircle is guaranteed to be twice its radius.
C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.
D. The radius of a MyCircle object can be set without affecting its diameter.

QUESTION NO: 28
Which is a valid identifier?
A. false
B. default
C. _object
D. a-class

填空
QUESTION NO: 1

作用域public,private,protected,以及不写时的区别?

QUESTION NO: 2
Given:
11. int x = 3;
12. int y = 1;
13. if (x = y) {
14. System.out.println(“x = “ + x);
15. }
What is the result?

QUESTION NO: 3
Given:
1. public class Test {
2. public static void aMethod() throws Exception {
3. try {
4. throw new Exception();
5. } finally {
6. System.out.println(“finally”);
7. }
8. }
9. public static void main(String args[]) {
10. try {
11. aMethod();
12. } catch (Exception e) {
13. System.out.println(“exception”);
14. }
15. System.out.println(“finished”);
16. }
17. }
What is the result?

QUESTION NO: 4
1. public class Delta {
2. static boolean foo(char c) {
3. System.out.print(c);
4. return true;
5. }
6. public static void main( String[] argv ) {
7. int i =0;
8. for ( foo(‘A’); foo(‘B’)&&(i 9. i++ ;
10. foo(‘D’);
12. }
13. }
14. }
What is the result?

QUESTION NO: 5
1. public class SwitchTest {
2. public static void main(String[] args) {
3. System.out.println(“value = “ + switchIt(4));
4. }
5. public static int switchIt(int x) {
6. int j = 1;
7. switch (x) {
8. case 1: j++;
9. case 2: j++;
10. case 3: j++;
11. case 4: j++;
12. case 5: j++;
13. default: j++;
14. }
15. return j + x;
16. }
17. }
What is the result?

QUESTION NO: 6
Given:
1. public class Test {
2. public static String output =””;
3.
4. public static void foo(int i) {
5. try {
6. if(i==1) {
7. throw new Exception();
8. }
9. output += “1”;
10. }
11. catch(Exception e) {
12. output += “2”;
13. return;
14. }
15. finally {
16. output += “3”;
17. }
18. output += “4”;
19. }
20.
21. public static void main(String args[]) {
22. foo(0);
23. foo(1);
24.
25. }
26. }
What is the value of the variable output at line 23?

QUESTION NO: 7
Given:
1. public class X {
2. public static void main(String [] args) {
3. try {
4. badMethod();
5. System.out.print(“A”);
6. }
7. catch (Exception ex) {
8. System.out.print(“B”);
9. }
10. finally {
11. System.out.print(“C”);
12. }
13. System.out.print(“D”);
14. }
15. public static void badMethod() {}
17. }
What is the result?

QUESTION NO: 8
Given:
11. int i = 0;
12. while (true) {
13. if(i==4) {
14. break;
15. }
16. ++i;
17. }
18. System.out.println(“i=”+i);
What is the result?

QUESTION NO: 9
Given:
1. public class Alpha{
2. public static void main( string[] args ){
3. if ( args.length == 2 ) {
4. if ( args.[0].equalsIgnoreCase(“-b”) )
5. System.out.println( new Boolean( args[1] ));
6. }
7. }
8. }
And the code is invoked by using the command:
java Alpha –b TRUE
What is the result?

QUESTION NO: 10
Given:
11. String a = “ABCD”;
12. String b = a.toLowerCase();
13. b.replace(‘a’, ‘d’);
14. b.replace(‘b’, ‘c’);
15. System.out.println(b);
What is the result?

QUESTION NO: 11
Given:
1. public class Foo {
2. public static void main (String [] args) {
3. StringBuffer a = new StringBuffer (“A”);
4. StringBuffer b = new StringBuffer (“B”);
5. operate (a,b);
6. system.out.printIn{a + “,” +b};
7. )
8. static void operate (StringBuffer x, StringBuffer y) {
9. x.append {y};
10. y = x;
11. )
12. }

QUESTION NO: 12
Exhibit:
1. Public class test (
2. Public static void stringReplace (String text) (
3. Text = text.replace (‘j’ , ‘i’);
4. )
5.
6. public static void bufferReplace (StringBuffer text) (
7. text = text.append (“C”)
8. )
9.
10. public static void main (String args[]} (
11. String textString = new String (“java”);
12. StringBuffer text BufferString = new StringBuffer (“java”);
13.
14. stringReplace (textString);
15. bufferReplace (textBuffer);
16.
17. System.out.printLn (textString + textBuffer);
18. }
19. )
What is the output?
问答
1、jsp有哪些内置对象?作用分别是什么?
2、jsp有哪些动作?作用分别是什么?
3、JSP中动态INCLUDE与静态INCLUDE的区别?
4、Servlet的生命周期?
5、请写一个最基本的Servlet类
6、用JAVA实现一种排序?

Tags in this post...

面试题 相关文章推荐
如何在Cookie里面保存Unicode和国际化字符
May 25 面试题
写出一个方法实现冒泡排序
Jul 08 面试题
如果NULL和0作为空指针常数是等价的,那我到底该用哪一个
Sep 16 面试题
什么是Rollback Segment
Apr 22 面试题
程序员机试试题汇总
Mar 07 面试题
应届生.NET方向面试题
May 23 面试题
什么是静态路由,其特点是什么?什么是动态路由,其特点是什么?
Jul 26 面试题
介绍一下结构化程序设计方法和面向对象程序设计方法的区别
Jun 27 面试题
现在输入n个数字,以逗号,分开;然后可选择升或者降序排序;按提交键就在另一页面显示按什么排序,结果为,提供reset
Nov 09 面试题
中科前程Java笔试题
Nov 20 面试题
UNIX文件系统常用命令
May 25 面试题
为什么要使用servlet
Jan 17 面试题
纬创Java面试题笔试题
Oct 02 #面试题
包装类的功能、种类、常用方法
Jan 27 #面试题
怎样声明接口
Sep 19 #面试题
群胜软件Java笔试题
Sep 29 #面试题
类、抽象类、接口的差异
Jun 13 #面试题
抽象方法、抽象类怎样声明
Oct 25 #面试题
介绍java中初始化块的使用
Sep 11 #面试题
You might like
php 数组的指针操作实现代码
2011/02/08 PHP
php中过滤非法字符的具体实现
2013/10/29 PHP
Codeigniter实现智能裁剪图片的方法
2014/06/12 PHP
php删除左端与右端空格的方法
2014/11/29 PHP
php编程中echo用逗号和用点号连接的区别
2016/03/26 PHP
php自定义扩展名获取函数示例
2016/12/12 PHP
Yii2框架配置文件(Application属性)与调试技巧实例分析
2019/05/27 PHP
jQuery 使用手册(七)
2009/09/23 Javascript
JS OOP包机制,类创建的方法定义
2009/11/02 Javascript
CutePsWheel javascript libary 控制输入文本框为可使用滚轮控制的js库
2010/02/07 Javascript
javascript中创建对象的三种常用方法
2010/12/30 Javascript
E3 tree 1.6在Firefox下显示问题的修复方法
2013/01/30 Javascript
javascript中match函数的用法小结
2014/02/08 Javascript
Javascript中的String对象详谈
2014/03/03 Javascript
js+ajax实现获取文件大小的方法
2015/12/08 Javascript
jQuery实现可以控制图片旋转角度效果(附demo源码下载)
2016/01/27 Javascript
JavaScript中数组的22种方法必学(推荐)
2016/07/20 Javascript
Angular实现跨域(搜索框的下拉列表)
2017/02/16 Javascript
基于构造函数的五种继承方法小结
2017/07/27 Javascript
JavaScript创建对象的常用方式总结
2018/08/10 Javascript
element-ui 的el-button组件中添加自定义颜色和图标的实现方法
2018/10/26 Javascript
详解微信小程序-扫一扫 wx.scanCode() 扫码大变身
2019/04/30 Javascript
浅谈Layui的eleTree树式选择器使用方法
2019/09/25 Javascript
vue data恢复初始化数据的实现方法
2019/10/31 Javascript
ES6函数实现排它两种写法解析
2020/05/13 Javascript
[01:46]2018完美盛典章节片——坚守
2018/12/17 DOTA
Python使用ntplib库同步校准当地时间的方法
2016/07/02 Python
python高效过滤出文件夹下指定文件名结尾的文件实例
2018/10/21 Python
Python操作配置文件ini的三种方法讲解
2019/02/22 Python
Python字典生成式、集合生成式、生成器用法实例分析
2020/01/07 Python
旅游管理专业学生求职信
2013/09/28 职场文书
物流管理专业应届生求职信
2013/11/21 职场文书
酒店开业庆典主持词
2014/03/21 职场文书
股东协议书
2014/04/14 职场文书
幼儿园教师岗位职责
2015/04/02 职场文书
安装harbor作为docker镜像仓库的问题
2022/06/14 Servers