有些面试题目,麻烦有哪位帮个忙,非常着急,谢谢你们了。
如能发到邮箱,更为感激,再次谢谢。JAVA笔试题(笔试时间60分钟)
一、每道题可能包括一个或者多个正确答案(每小题3分,总计60分)
1.选择编译运行下列代码时的运行结果。
public class MyClass {public static void main(String arguments[]){amethod(arguments);}public void amethod(String[] arguments){System.out.println(arguments);System.out.println(arguments[1]);}}A) error Can't make static reference to void amethod.;
B) error method main not correct
C) error array must include parameter
D) amethod must be declared with String
2.下列哪些代码段可以通过编译。
A)import java.awt.*;package Mypackage;class Myclass {}B) package MyPackage;import java.awt.*;class MyClass{}C) /*This is a comment */package MyPackage;import java.awt.*;class MyClass{}D) /*This is a comment */package MyPackage;import java.awt.*;class MyClass{
public static void main(){

}
3.下列代码段在用命令行java myprog good morning运行时,会打印出什么结果 
public class myprog{public static void main(String argv[]) 
{System.out.println(argv[2])}
}
A) myprogB) goodC) morningD) Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"
4.请选择下列代码的运行结果。
public class MyClass{static int i; public static void main(String argv[]){System.out.println(i);}} A) Error Variable i may not have been initializedB) nullC) 1D) 0
5.下列哪些代码段可以通过编译。
A) int i=0;if(i){System.out.println("Hello");}B) boolean b = true;boolean b2 = true;if(b==b2){System.out.println("So true");}C) int i=1;int j = 2;if(i ==1|| j==2)System.out.println("OK");D)int i=1;int j = 2;if(i ==1 &| j==2)System.out.println("OK");
6.如果当前路经下不存在Hello.txt文件,则下列代码的运行结果是什么?
import java.io.*;public class Mine {public static void main(String argv[]){Mine m = new Mine();System.out.println(m.amethod());}public int amethod(){try {FileInputStream dis = new FileInputStream("Hello.txt");}catch (FileNotFoundException fne) {System.out.println("No such file found");return -1;}catch(IOException ioe) {} finally{System.out.println("Doing finally");}return 0;}}A) No such file foundB) No such file found ,-1C) No such file found, doing finally, -1D) 0
7.下列代码是对Demo类的定义:
Given the following code for the Demo class:
public class Demo{private int[] count;public Demo(){ count=new int[10];}public void setCount(int ct,int n){ count[n]=ct;}public void showCount(int n){System.out.println("Count is "+count[n]);}public int getCount(int n){ return count[n];}}
创建Demo类的实例后用参数9调用showCount方法,运行结果是什么?
a) NullPointerException例外被抛出;
b) 运行结果显示 "Count is 0".c) ArrayIndexOutOfBoundsException例外被抛出;
d) 运行结果显示"Count is null".
8.请选择下列代码的运行结果
1. public class Logic{2. static long sixteen=0x0010;3. static public void main(String args[]){4. long N=sixteen>>4:5. System.out.println("N= "+N);6. }7. }
a) 编译器在第4行int型数值向long型数值转换时出错;
b) 程序通过编译,运行结果为 "N=0"
c) 程序通过编译,运行结果为 "N=1".d) 抛出运行时异常;
9.请选出下列代码中所有合法的java代码。
a) String A="abcdefg"; A-="cde";
b) String A="abcdefg";A+="cde";
c) Integer J=new Integer(27);J+=7;
d) Integer J=new Integer(27);J--;
10.在一个应用中有下列代码段:
1. public String setFiletype(String fname){2. int p=fname.indexOf('.');3. if(p>0) fname=fname.substring(0,p);4. fname+=".TXT";5. return fname;6. }
同时包含另一段代码:
7. String TheFile="Program.java";8. File F=new File(setFileType(TheFile));9. System.out.println("Created "+TheFile);第9行代码将打印出什么结果?
a) "Created Program.java"b) "Created Program.txt"c) "Created Program.java.txt"
11.请选择编译和运行下列代码的结果。
1. public class EqualsTest{2. public static void main(String args[]){3. Long LA=new Long(7);4. Long LB=new Long(7);5. if(LA==LB) System.out.println("Equal");6. else System.out.println("Not Equal");7. }8. }
a) The program compiles but throws a runtime exception in line 5.b) The program compiles and prints "Not Equal";c) The program compiles and prints "Equal".
12.下列代码是对Demo类的定义::
public class Demo extends Base{private int count;public Demo(){System.out.println("A Demo object has been created");}protected void addOne() {count++; }}
下列选项对“count”变量描述正确的是:
a) 当创建Demo类的对象实例时,count变量的值是0;
b) 当创建Demo类的对象实例时,count变量还未定义;.c)  Base类的对象可以包含修改count变量的方法;
d) 修改count变量的唯一方法是调用addOne方法;
13.在下列方法中,当对象Ob不是Long类的实例时,如果想“短路”第2行的测试语句, X的位置应该填入哪一个逻辑操作符?
1. long Test(Object ob){2. if(Ob instanceof Long X ((Long)Ob).longValue()>999){3. return((Long)Ob).longValue();4. }5. return -1L;6. }
a) &&
b) ||
c) &
d) |
14.下列哪一条语句能正确表达float变量X是否包含特殊值“Not a Number”?
a) if(X instanceof Float.NaN)b) if(X==Float.NaN)c) if(Float.isNaN(X))
15.下列方法在N为67时,返回值是多少?
public int MaskOff(int N){return N^3;}
a) 3.b) 64.c) 67.d) 0.
16.下列程序是Derived.java文件的完整内容,当编译该文件时,会出现什么情况?
public class Base extends Object{
String objType;
public Base(){ objType="I am a Base type";
}
}
public class Derived extends Base{
public Derived() { objType="I am a Derived type";
}
public static void main(String args[]){
Derived D=new Derived();
}
}
a) 会创建两个class文件,Base.class 和Derived.class ;
b) 编译器会提示第一行出错;
c) 编译器会提示第7行出错; 
17.测试下列代码,运行结果是什么?
public class Calc {
public static void main (String args []) {
int total = 0;
for (int i = 0, j = 10; total > 30; ++i, --j) {
System.out.println(" i = " + i + " : j = " + j);
total += (i + j);
}
System.out.println("Total " + total);
}
}
 
A. 抛出运行时异常;Produce a runtime error
B. 编译时抛出错误;Produce a compile time error
C. 输出 "Total 0"
D. 输出下列内容:
i = 0 : j = 10
i = 1 : j = 9
i = 2 : j = 8
Total 30
18.用于追加和更新文件的I/O操作是下列哪一个类?
a) RandomAccessFileb) Outputstreamc) DataOutputstream
19.当handleEvent()方法返回true时,下列描述正确的是:
a) 该事件将被组件捕获;
b) action()方法将捕获该事件;
c) 该事件将被父类的方法super.handleEvent()捕获;
d) 什么也不做;
20.在下列代码的<<<operator>>>位置上,哪些选项可以返回true。
class StringTest{public static void main(String[] args){//// String comparing//String a,b;StringBuffer c,d;c=new StringBuffer("Hello");a=new String("Hello");b=a;d=c;if( <<<operator>>> ) {}}} // class
a) b.equals(a)b) b==ac) d==cd) d.equals(c)
二、编程题:
1.(15分)
如果f(n+2)=f(n)+2×f(n +1)
并且f(0)=A,f(1)=B  A,B都是整数
请你设计一个类:包含以下方法
SetBasicValue:设置A和B的值
GetFValue:计算f(n)的值
请写出类FValuer的实现
2.(25分)
已知有一个类MyBean,类文件如下:public class MyBean {
  Object midData; /*中间数据,用来存放多个业务方法之间业务数据*/
  public MyBean () {
init();
  }  public init(){
    //进行相应的初试化工作,非常耗费资源
  }  //&nbsp;其他的应用方法…
}由于生成一个MyBean的实例非常耗费资源,而且我们的应用频繁生成和销毁,造成效率很低。因此我们需要设计一个MyBean的池,从而用来缓存一定数量MyBean的实例。这样其他类来使用MyBean的时候就可以直接从MyBeanPool中取已经生成的MyBean
MyBeanPool包括如下基本的功能:
能够设置池中MyBean实例的个数
能够生成MyBean实例
能够获取一个MyBean的实例
当不需要使用时,可以释放这个实例
(MyBean有状态的:也就是多个方法之间需要通过)
请你写出MyBeanPool的实现。