java 高级程序员面试试题汇总.doc
文本预览下载声明
填空题
下列程序中构造了一个SET并且调用其方法add(),输出结果是
public class A{
public int hashCode(){return 1;}
public Boolean equals(Object b){return true}
public static void main(String args[]){ Set set=new HashSet();
set.add(new A());
set.add(new A());
set.add(new A());
System.out.println(set.size());
}
}
答案:1
下列程序的运行结果是
class A{
class Dog{
private String name;
private int age;
public int step;
Dog(String s,int a)
{
name=s;
age=a;
step=0;
}
public void run(Dog fast)
{
fast.step++;
}
}
public static void main (String args[])
{
A a=new A();
Dog d=a.new Dog(Tom,3);
d.step=25;
d.run(d);
System.out.println(d.step);
}
}
答案:答案:7
下列代码不能编译的原因是
Class A{
Private int x;
Public static void main(String args[])
{
new B();
}
class B{
B(){System.out.println(x);
}
}
}
答案:I am Tom
How do you do?
5. 给定下面的未完成的代码片断:
public class Example{
int x,y;
public Example(int a){
…
x = a;
}
public Example(int a, int b){
//和上面一个参数的构造方法做同样的操作,包括赋值
x=a y = b;
}
}
如果要用最简捷的一行代码实现//和上面一个参数的…注释所指出的功能,请写出你认为最合适的一行代码:
答案:
如果有一个类MyFrame是Frame的子类,能够被不同包中的类所使用,同时又能够为线程提供运行代码(run()方法),请写出该类的声明头。 你的解答:
答案:
请阅读下列程序代码,然后将程序的执行结果补充完整。 程序代码: class?throwsException? { ?static?void?Proc(int?sel)?throws?ArithmeticException,ArrayIndexOutOfBoundsException ?{ ??System.out.println(In?Situation+sel); ??if(sel==0){ ????System.out.println(no?Exception?caught); ????return; ??} ??else?if(sel==1){ ????int?iArray[]=new?int[4]; ????iArray[1]=3; ??} ?} ?public?static?void?main(String[]?args)? ?{ ???try{ ?????Proc(0); ?????Proc(1); ???}catch(ArrayIndexOutOfBoundsException?e){ ?????System.out.println(Catch+e); ???}finally{ ?????System.out.println(in?Proc?finally); ???} ?} } 执行结果: In?Situation0 no?Exception?caught __In?Situation1____ in?Proc?finally
选择题
4.指出下列程序运行的结果 B
public class Example{
String str=new String(good);
char[]ch={a,b,c};
public static v
显示全部