一套大公司的面试题(欢迎提供答案)

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 107 收藏 0 点赞 0 评论 0

一、选择题
1、关于垃圾收集的哪些叙述是正确的(  C ):
A.程序开发者必须自己创建一个线程进行内存释放的工作
B.垃圾收集允许程序开发者明确指定并立即释放该内存
C.垃圾收集将检查并释放不再使用的内存
D.垃圾收集能够在期望的时间释放被java对象使用的内存
2、下面的哪些赋值语句是不正确的(   ):
A.float f=11.1;
B.double d=5.3E12;
C.double d=3.14159;
D.double d=3.14D;
3、下面关于变量及其范围的陈述哪些是不正确的( AB  ):
A.实例变量是类的成员变量
B.实例变量用关键字static声明
C.在方法中定义的局部变量在该方法被执行时创建
D.局部变量在使用前必须被初始化
4、下列关于修饰符混用的说法,错误的是(AD):
A.abstract不能与final并列修饰同一个类
B.abstract类中不可以有private的成员
C.abstract方法必须在abstract类中
D.static方法中能处理非static的属性
5、容器Panel和Applet缺省使用的布局编辑策略是( B):
A、BorderLayout  B、FlowLayout      C、GridLayout      D、CardLayout
6、以下标识符中哪项是不合法的(  C  ): 在Java语言中,标识符是以字母、下划线(…)或美元符($)开头,由字母、数字、下划线(一)或美元符($)组成的字符串。标识符区分大小写,长度没有限制。除以上所列几项之外,标识符中不能含有其他符号,当然也不允许插入空格。
A、 BigMeaninglessName                     B、$int
C、1 st                                    D、$1
7、main方法是Java  Application程序执行的入口点,关于main方法的方法头以下哪项是合法的( BCD   ):
A、    public  static  void  main()
B、    public  static  void   main(String[ ]  args)
C、    public  static int  main(String[ ]  arg)
D、    public  void  main(String  arg[ ])
8、执行完以下代码int [ ]  x = new  int[25];后,以下哪项说明是正确的(   D ):
A、    x[24]为0
B、    x[24]未定义
C、    x[25]为0
D、    x[0]为空
9、以下代码段执行后的输出结果为(     ):
int  x=3; int  y=10;
System.out.println(y%x);
A、0
B、1
C、2
D、3
10、以下哪个表达式是不合法的(    ):
A、String  x=”Hello”;   int  y=9;   x+=y;
B、String  x=”Hello”;   int  y=9;  if(x= =y)  { }
C、String  x=”Hello”;  int  y=9;  x=x+y;
D、String  x=null;  int  y=(x!=null)&&(x.length()>0) ? x.length : 0
11、编译运行以下程序后,关于输出结果的说明正确的是 (    ):
public  class   Conditional{
public  static  void  main(String  args[  ]){
int  x=4;
System.out.println(“value  is  “+ ((x>4) ? 99.9 :9));
}
}
A、    输出结果为:value  is  99.99
B、    输出结果为:value  is  9
C、    输出结果为:value  is  9.0
D、    编译错误
12、以下声明合法的是(     ):
A、    default  String  s;
B、    public  final  static  native  int  w( )
C、    abstract  double  d;
D、    abstract  final  double  hyperbolicCosine( )
13、关于以下application的说明,正确的是(    ):
1.  class   StaticStuff
2. {
3.                  static  int  x=10;
4.                  static  { x+=5;}
5.                  public  static  void  main(String  args[ ])
6.                  {
7.                       System.out.println(“x=” + x);
8.                  }
9.                  static  { x/=3;}
10.   }
A、 4行与9行不能通过编译,因为缺少方法名和返回类型
B、 9行不能通过编译,因为只能有一个静态初始化器
C、 编译通过,执行结果为:x=5
D、编译通过,执行结果为:x=3
14、关于以下程序代码的说明正确的是(   ):
1.class  HasStatic{
2.    private  static  int  x=100;
3.    public  static  void  main(String  args[  ]){
4.        HasStatic  hs1=new  HasStatic(  );
5.        hs1.x++;
6.        HasStatic  hs2=new  HasStatic(  );
7.        hs2.x++;
8.        hs1=new  HasStatic( );
9.        hs1.x++;
10.       HasStatic.x- -;
11.       System.out.println(“x=”+x);
12.   }
13.}
A、5行不能通过编译,因为引用了私有静态变量
B、10行不能通过编译,因为x是私有静态变量
C、程序通过编译,输出结果为:x=103
D、程序通过编译,输出结果为:x=102
15、以下选项中循环结构合法的是(    ):
A、while (int  i<7){
i++;
System.out.println(“i is “+i);
}
B、int  j=3;
while(j){
System.out.println(“ j  is “+j);
}
C、int  j=0;
for(int  k=0; j + k !=10; j++,k++){
System.out.println(“ j  is “+ j + “k  is”+ k);
}
D、int  j=0;
do{
System.out.println( “j  is “+j++);
if (j = = 3) {continue  loop;}
}while  (j<10);

二、简答题(40分)
1.    写出下列程序的运行结果
public class Cat
{
void mi( ) throws NullPointerException
{
System.out.println( “Cat mi mi .. “ );
}
}
public class SmallCat extends Cat
{int i=8;
void mi( ) throws Exception
{
System.out.println( “SmallCat mi mi .. “ );
}
public static void main( String[] a ) throws Exception
{
Cat cat = new SmallCat();
cat.mi();
}
}

写出下列程序的运行结果
interface Playable {
void play();
}
interface Bounceable {
void play();
}
interface Rollable extends Playable, Bounceable {
Ball ball = new Ball(“PingPang”);
}
class Ball implements Rollable {
private String name;
public String getName() {
return name;
}
public Ball(String name) {
this.name = name;
}
public void play() {
ball = new Ball(“Football”);
System.out.println(ball.getName());
}
}

写出下列程序的运行结果
class Value{
public int i = 15;
}
public class Test{
public static void main(String argv[]){
Test t = new Test();
t.first();
}
public void first(){
int i = 5;
Value v = new Value();
v.i = 25;
second(v, i);
System.out.println(v.i);
}
public void second(Value v, int i){
i = 0;
v.i = 20;
Value val = new Value();
v = val;
System.out.println(v.i + ” ” + i);
}
}

写出下列程序的运行结果
class MyThread extends Thread{
public void run(){
System.out.println(“MyThread: run()”);
}
public void start(){
System.out.println(“MyThread: start()”);
}
}
class MyRunnable implements Runnable{
public void run(){
System.out.println(“MyRunnable: run()”);
}
public void start(){
System.out.println(“MyRunnable: start()”);
}
}
public class MyTest {
public static void main(String args[]){
MyThread myThread  =  new MyThread();
MyRunnable myRunnable = new MyRunnable();
Thread thread  =  new Thread(myRunnable);
myThread.start();
thread.start();
}
}
2.    1~100共一百个自然数,放入一个99个元素的数组a[99],要求用java语言编写出一个尽量简单的程序,找出没有被放入数组的这个数。

3.    简要叙述一下什么是数据库连接池,有何作用。

4.    简要描述Struts,spring,hibernate?

评论列表
文章目录