欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【深圳X金技术公司】Java笔试题

程序员文章站 2022-03-02 22:16:14
...

前言
今年 8 月份,一个同学内推的面试,好吧,笔试题我做得一塌糊涂,然后被面试官一顿血虐。

正文

一 选择题
1)关于 C++ / Java 类中 static 成员和对象成员的说法正确的是()

  • A static 成员变量在对象构造时生成
  • B static 成员函数在对象成员函数中无法使用
  • C 虚成员函数不可能时 static 成员函数
  • D static 成员函数不能访问 static 成员变量

2)袋中有红球,黄球,白球各一个,每次任意取一个又放回,如此连续抽取 3 次,则下列事件中概率是 8/9 的是()

  • A 颜色不全相同
  • B 颜色全相同
  • C 颜色全不同
  • D 颜色无红色

3)通常不采用 () 方法来解除死锁

  • A 终止一个死锁进程
  • B 终止所有死锁进程
  • C 从死锁进程处抢夺资源
  • D 从非死锁进程处抢夺资源

4)32 位系统环境,编译选项为 4 字节对齐,那么 sizaof (A) 和 sizeof(B)分别()

structA{
 int a;
 short b;
 int c;
 char d;
}
structB{
 int a;
 short b;
 char d;
 int c;
}
  • A 16, 16
  • B 16, 12
  • C 13, 12
  • D 11, 16
  1. 下面() 是合法的 Java 标识符。
  • A #_pound
  • B _underscore
  • C 5Interstate
  • D class
  1. 当需要在文件中写入字符而不是字节时,在下面的类中最好选用()类。
  • A java.io.RandomAccessFile
  • B java.io.PrintWriter
  • C java.io.PrintStream
  • D java.io.PrintOutputStream
  1. 下面这段代码会产生 () 个 String 对象。
String s1 = "hello";
String s2 = s1.substring(2,3);
String s3 = s1.toString();
String s4 = new StringBuffer(s1).toString();
  • A、1
  • B、2
  • C、3
  • D、4

8)Swtich 不能作用在下面那个数据类型上?

  • A、int
  • B、short
  • C、String
  • D、byte
  1. 对 hashmap ,arraylist 内存储的数据是否有序的描述那个是正确的?()
  • A 、无序,有序
  • B、 有序,有序
  • C、 无序,无序
  • D、 有序,无序

10)关于下面程序,()的结论是正确的。

class J_SubClass extends J_Test{}
public class J_Test{
	J_Test(int i ){
	System.out.println(i);
 }
 public static void main(String[] args){
	J_SubClass a = new J_SubClass();
 }
}
  • A、不能通过编译,因为类 J_Test 没有定义无参数的构造方法
  • B、 不能通过编译,因为类 J_SubClass 没有定义无参构造方法
  • C、不能通过编译,因为没有实现 J_SubClass( int i) 的构造方法
  • D、可以成功通过编译

二、问答题
1)读程序,写出和程序输出格式一致的输出结果。

public class J_Test{
	public static void mian(String[] args){
  			 int sum= 0;
   		outer:for(int i = 1; i < 10; ++1){
			inner:for(int j = 1; j < 3; ++j){
 					sum +=j;
 				if(i + j > 6){
 					break inner;
 				}
			}
			System.out.println("sum = " + sum);
		}
 	}
}
  1. 读程序,写出和程序输出格式一致的输出结果。
public class J_Test{
	public static void mb_method(int i){
  			try{
				if(i == 1){
					thow new Exception();
				   System.out.println("1");
				}catch(Exception e){
				   System.out.println("2");
				   return;
				}finally{
					System.out.println("3");
				}
			}
			System.out.println("4");
		}
		public static void mian(String[] args){
		mb_method(0);
		mb_method(1);
		}
}
  1. 读程序,写出和程序输出格式一致的输出结果。
public class J_Test{
	public static void mb_method(StringBuffer x, StringBuffer y){
 			x.append(y);
 			y = x;
	}
	public static void mian(String[] args){
  			StringBuffer a = new StringBuffer("A");
  			StringBuffer b = new StringBuffer("B");
  			mb_method(a, b);
			System.out.println(a + "," + b);
	}
}
  1. 读程序,写出和程序输出格式一致的输出结果。
	int func(int m, int n){
	  if(m%n == 0){
	  	return n;
	  }else{
	  	return fuc(n, m%n);
	  }
	}

请问 func(2012, 2020) 的结果是( )

  1. 读程序,写出和程序输出格式一致的输出结果。
 int i = 0, j = 9;
 do{
 	if(i++ > --j){
 		break;
 	}
 	while(i < 4);
   }
	System.out.println("i = " + i + "and j = "+ j);
   }
}