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

面试题 相关文章推荐
北京银河万佳Java面试题
Mar 21 面试题
写一个函数返回1+2+3+…+n的值(假定结果不会超过长整型变量的范围)
Sep 05 面试题
聚网科技C++面试笔试题
Sep 01 面试题
struct和class的区别
Nov 20 面试题
SQL SERVER面试资料
Mar 30 面试题
武汉世纪畅想数字传播有限公司 .NET笔试题
Jun 13 面试题
什么情况下你必须要把一个类定义为abstract的
Jan 06 面试题
介绍一下MD5加密算法
Nov 12 面试题
简述进程的启动、终止的方式以及如何进行进程的查看
Jul 12 面试题
英智兴达软件测试笔试题
Oct 12 面试题
Ruby中的保护方法和私有方法与一般面向对象程序设计语言的一样吗
May 01 面试题
顺丰快递Java软件工程师面试题
Jul 31 面试题
纬创Java面试题笔试题
Oct 02 #面试题
包装类的功能、种类、常用方法
Jan 27 #面试题
怎样声明接口
Sep 19 #面试题
群胜软件Java笔试题
Sep 29 #面试题
类、抽象类、接口的差异
Jun 13 #面试题
抽象方法、抽象类怎样声明
Oct 25 #面试题
介绍java中初始化块的使用
Sep 11 #面试题
You might like
php引用地址改变变量值的问题
2012/03/23 PHP
使用PHP求两个文件的相对路径
2013/06/20 PHP
php获取CSS文件中图片地址并下载到本地的方法
2014/12/02 PHP
PHP数组内存利用率低和弱类型详细解读
2017/08/10 PHP
基于ThinkPHP5框架使用QueryList爬取并存入mysql数据库操作示例
2019/05/25 PHP
阿里对象存储OSS在laravel框架中的使用方法
2019/10/13 PHP
PHP上传图片到数据库并显示的实例代码
2019/12/20 PHP
javascript实现数独解法
2015/03/14 Javascript
jQuery中get方法用法分析
2016/12/07 Javascript
Angular.js实现注册系统的实例详解
2016/12/18 Javascript
javascript将url解析为json格式的两种方法
2017/08/18 Javascript
老生常谈JS中的继承及实现代码
2018/07/06 Javascript
使用javascript做时间倒数读秒功能的实例
2019/01/23 Javascript
可能被忽略的一些JavaScript数组方法细节
2019/02/28 Javascript
layui实现多图片上传并限制上传的图片数量
2019/09/26 Javascript
vue+canvas实现拼图小游戏
2020/09/18 Javascript
vue element-ui中table合计指定列求和实例
2020/11/02 Javascript
python中getattr函数使用方法 getattr实现工厂模式
2014/01/20 Python
python中元类用法实例
2014/10/10 Python
深入学习python的yield和generator
2016/03/10 Python
python实现class对象转换成json/字典的方法
2016/03/11 Python
python 字符串转列表 list 出现\ufeff的解决方法
2017/06/22 Python
Python3实现购物车功能
2018/04/18 Python
Python3实现取图片中特定的像素替换指定的颜色示例
2019/01/24 Python
WxPython实现无边框界面
2019/11/18 Python
python实现UDP协议下的文件传输
2020/03/20 Python
Python Numpy中数据的常用保存与读取方法
2020/04/01 Python
法国创作个性化T恤衫和其他定制产品平台:Tostadora
2018/04/08 全球购物
护士自我评价范文
2014/01/25 职场文书
追悼会主持词
2014/03/20 职场文书
学生检讨书范文
2014/10/30 职场文书
2015小学教师年度考核工作总结
2015/05/12 职场文书
2015年教师见习期工作总结
2015/05/20 职场文书
《作风建设永远在路上》心得体会
2016/01/21 职场文书
MySQL外键约束(FOREIGN KEY)案例讲解
2021/08/23 MySQL
基于Python实现nc批量转tif格式
2022/08/14 Python