java真实面试题(2)

1,递归算法的实行过程,一般来说,可以分为()和()两个阶段,若一个问题的求解既可以用递归也可以用递推时,则往往用(),因为()。贪婪法是一种()的算法。

答:递归算法分为推和回两个阶段,递推效率更高,贪婪法是一种不求最优只求满意的算法。

2,填写下面的程序,生成以下二维数组:

1   2   3   4      int i;

5   6   7   8      int[][] arrTemp=(  );

9  10 11 12      for(  )

13 14 15 16      arrTemp(  ,  )=(    );

 答:int[4][4];for(i=0;i<16;i++){arrTemp[i/4][i%4]=i+1}

3,代码查错并说明原因

abstract class Something{
  private abstract String doSomething()
}
public class Something{  
  public int addOne(final int x){
    return ++x;
  }
}

答:首先类重名了,然后抽象方法不能private,final的变量不能改变,所以不能++x;

4,手机号的正则表达式

答:^1[3|4|5|8][0-9]\d{8}$

5,以下程序的输出结果

 class HelloA {
	public HelloA(){
		System.out.println("Hello A");
	}
	{
		System.out.println("I'm A class");
	}
	static{System.out.println("Static A");}
}

 public class HelloB extends HelloA {
	public HelloB(){
		System.out.println("Hello B");
	}
	{
		System.out.println("I'm B class");
	}
	static{System.out.println("Static B");}
	public static void main(String[] args) throws CloneNotSupportedException{
		new HelloB();
	}
}

  答:先执行static方法,从父类到子类,然后代码域在构造方法之前执行,所以是

static A
Static B
I'm A class
hello A
i'm B class
hello B

6,以下程序输出结果

String str1 = new String("hello");
String str2 = new String("hello");
System.out.print(str1==str2);
String  str3 = "hello",str4="hello";
System.out.print(str3==str4);

答:对象类型不相等,字符串常亮相等,所以是 false true。

7,重写的关键词和作用

答:关键词 overwrite?? 作用:重写是为了增强类的重用性和复用性,扩展性????

8,hashmap遍历方法

答:foreach entryset;foreach keyset;entryset.iter;keyset.iter;

八道java题,其他设计前段和数据库的先不写了。题很奇怪,杭州某信息金融公司。

posted @ 2019-06-25 15:52  你又来写博客了  阅读(297)  评论(0)    收藏  举报