java高级工程师面试题及答案
资料仅供参考
一: 选择题
1. 关于以下程序代码的说明正确的是( D )
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
2. 下列关于for循环和while循环的说法中哪个是正确的?( B )
资料仅供参考
A.while循环能实现的操作,for循环也都能实现
B.while循环判断条件一般是程序结果,for循环判断条件一般是非程序结果 C.两种循环任何时候都可替换
D.两种循环结构中都必须有循环体,循环体不能为空
3. 以下选项中循环结构合法的是( C )
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);
4. 给出下面代码段, 哪行将引起一个编译时错误?( D )
资料仅供参考
1) public class Test { 2) int n = 0; 3) int m = 0;
4) public Test(int a) { m=a; }
5) public static void main(String arg[]) { 6) Test t1,t2; 7) int j,k; 8) j=3; k=5;
9) t1=new Test(); 10) t2=new Test(k); 11) } 12) }
A. 行1 B. 行4 行9 5. 下面的方法,当输入为2的时候返回值是多少?( D )
public int getValue(int i) { int result = 0; switch (i) { case 1:
result = result + i; case 2:
result = result + i * 2; case 3:
result = result + i * 3; }
return result; }
A 0 B 2 10
C. 行6 C 4 D.
D 资料仅供参考
二 : 简述题
1、描述一下 JVM 加载 class 文件的原理机制?
JVM 中类的装载是由 ClassLoader 和它的子类来实现的,Java ClassLoader 是一个重要的 Java 运行时系统组件。它负责在运行时查找和装入类文件的类。
2、heap 和 stack 有什么区别。
java 的内存分为两类,一类是栈内存,一类是堆内存。栈内存是指程序进入一个方法时, 会为这个方法单独分配一块私属存储空间,用于存储这个方法内部的局部变量,当这个方法 结束时,分配给这个方法的栈会释放,这个栈中的变量也将随之释放。
堆是与栈作用不同的内存,一般用于存放不放在当前方法栈中的那些数据,例如,使用 new 创立的对象都放在堆里,因此,它不会随方法的结束而消失。方法中的局部变量使用 final 修饰后,放在堆中,而不是栈中。
3、GC 是什么?为什么要有 GC?
GC 是垃圾收集的意思(Gabage Collection),内存处理是编程人员容易出现问题的地方, 忘
相关推荐: