前言
今年 8 月份,一个同学内推的面试,好吧,笔试题我做得一塌糊涂,然后被面试官一顿血虐。
正文
一 选择题
1)关于 C++ / Java 类中 static 成员和对象成员的说法正确的是()
2)袋中有红球,黄球,白球各一个,每次任意取一个又放回,如此连续抽取 3 次,则下列事件中概率是 8/9 的是()
3)通常不采用 () 方法来解除死锁
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;
}
下面这段代码会产生 () 个 String 对象。
String s1 = “hello”;
String s2 = s1.substring(2,3);
String s3 = s1.toString();
String s4 = new StringBuffer(s1).toString();
8)Swtich 不能作用在下面那个数据类型上?
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();
}
}
二、问答题
1)读程序,写出和程序输出格式一致的输出结果。
public class J_Test{
public static void main(String[] args){
int sum= 0;
outer:for(int i = 1; i < 10; ++i){
inner:for(int j = 1; j < 3; ++j){
sum +=j;
if(i + j > 6){
break inner;
}
}
System.out.println("sum = " + sum);
}
}
}
结果:
sum = 3
sum = 6
sum = 9
sum = 12
sum = 15
sum = 16
sum = 17
sum = 18
sum = 19
读程序,写出和程序输出格式一致的输出结果。
public class J_Test{
public static void mb_method(int i) {
try {
if (i == 1) {
throw 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 main(String[] args) {
mb_method(0);
mb_method(1);
}
}
运行结果:
1
3
4
2
3
读程序,写出和程序输出格式一致的输出结果。
public class J_Test{
public static void mb_method(StringBuffer x, StringBuffer y){
x.append(y);
y = x;
}
public static void main(String[] args){
StringBuffer a = new StringBuffer(“A”);
StringBuffer b = new StringBuffer(“B”);
mb_method(a, b);
System.out.println(a + “,” + b);
}
}
运行结果:
AB,B
读程序,写出和程序输出格式一致的输出结果。
int func(int m, int n){
if(m%n == 0){
return n;
}else{
return func(n, m%n);
}
}
请问 func(2012, 2020) 的结果是( 4 )
读程序,写出和程序输出格式一致的输出结果。
int i = 0, j = 9;
do {
if (i++ > --j) {
break;
}
}
while (i < 4) ;
System.out.println("i = " + i + "and j = " + j);
运行结果:
i = 4and j = 5