益模软件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...

面试题 相关文章推荐
名词解释WEB SERVICE,SOAP,UDDI,WSDL,JAXP,JAXM;JSWDL开发包的介绍。
Oct 27 面试题
使用useBean标志初始化BEAN时如何接受初始化参数
Feb 11 面试题
益模软件Java笔试题
Mar 27 面试题
在什么时候需要使用"常引用"
Dec 31 面试题
.net开发工程师面试题
Feb 25 面试题
Solaris操作系统的线程机制
Dec 23 面试题
新媒传信软件测试面试题
Feb 24 面试题
某公司部分笔试题
Nov 05 面试题
提高EJB性能都有哪些技巧
Mar 25 面试题
Java的类可以定义为Protected或者Private得吗
Sep 25 面试题
java程序员面试交流
Nov 29 面试题
Servlet如何得到服务器的信息
Dec 22 面试题
纬创Java面试题笔试题
Oct 02 #面试题
包装类的功能、种类、常用方法
Jan 27 #面试题
怎样声明接口
Sep 19 #面试题
群胜软件Java笔试题
Sep 29 #面试题
类、抽象类、接口的差异
Jun 13 #面试题
抽象方法、抽象类怎样声明
Oct 25 #面试题
介绍java中初始化块的使用
Sep 11 #面试题
You might like
PHP编码转换
2012/11/05 PHP
手把手教你打印出PDF(关于fpdf的简单应用)
2013/06/25 PHP
PHP实现链式操作的三种方法详解
2017/11/16 PHP
解决laravel上传图片之后,目录有图片,但是访问不到(404)的问题
2019/10/14 PHP
js动态为代码着色显示行号
2013/05/29 Javascript
实用的Jquery选项卡TAB示例代码
2013/08/28 Javascript
jQuery 顶部导航跟随滚动条滚动固定浮动在顶部
2014/06/06 Javascript
判断访客终端类型集锦
2015/06/05 Javascript
Bootstrap每天必学之按钮(一)
2015/11/24 Javascript
Js与Jq获取浏览器和对象值的方法
2016/03/18 Javascript
Google 地图控件集详解及实例代码
2016/08/06 Javascript
最常见和最有用的字符串相关的方法详解
2017/02/06 Javascript
[原创]SyntaxHighlighter自动识别并加载脚本语言
2017/02/07 Javascript
js实现无缝滚动图
2017/02/22 Javascript
BACKBONE.JS 简单入门范例
2017/10/17 Javascript
详解vue-cli 构建项目 vue-cli请求后台接口 vue-cli使用axios、sass、swiper
2018/05/28 Javascript
nodejs基础之多进程实例详解
2018/12/27 NodeJs
nodejs同步调用获取mysql数据时遇到的大坑
2019/03/02 NodeJs
layui type2 通过url给iframe子页面传值的例子
2019/09/06 Javascript
JS基础之逻辑结构与循环操作示例
2020/01/19 Javascript
[03:42]2014DOTA2国际邀请赛 第三日比赛排位扑朔迷离
2014/07/12 DOTA
[00:10]神之谴戒
2019/03/06 DOTA
python访问纯真IP数据库的代码
2011/05/19 Python
Python中文竖排显示的方法
2015/07/28 Python
Python函数中不定长参数的写法
2019/02/13 Python
Python面向对象程序设计类的多态用法详解
2019/04/12 Python
Python中list的交、并、差集获取方法示例
2019/08/01 Python
python logging.basicConfig不生效的原因及解决
2020/02/20 Python
jupyter lab文件导出/下载方式
2020/04/22 Python
CSS3利用text-shadow属性实现多种效果的文字样式展现方法
2016/08/25 HTML / CSS
吉力贝官方网站:Jelly Belly
2019/03/11 全球购物
Linux管理员面试题 Linux admin interview questions
2014/11/01 面试题
银行营业厅大堂经理岗位职责
2014/01/06 职场文书
建筑安全生产责任书
2014/07/22 职场文书
大学社团招新的通讯稿
2014/09/10 职场文书
原生JavaScript实现简单五子棋游戏
2021/06/28 Javascript