java笔试题一般几道_Java奇葩笔试题,你能做几道?

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:20   1031   0

1、下面代码中,在if处填写什么代码,可以使得输出结果为:AB

public static void main(String[] args) {

if ( ){//填写条件

System.out.print("A");

} else {

System.out.print("B");

}

}

2、 运算符问题,下面代码分别输出什么?

package test;

public class Test {

public static void main(String[] args) {

int i1 = 10, i2 = 10;

System.err.println("i1 + i2 = " + i1 + i2);

System.err.println("i1 - i2 = " + i1 - i2);

System.err.println("i1 * i2 = " + i1 * i2);

System.err.println("i1 / i2 = " + i1 / i2);

}

}

3、下面代码的结果是什么?还是抛出异常?

package test;

public class Test {

public void myMethod(String str) {

System.err.println("string");

}

public void myMethod(Object obj) {

System.err.println("object");

}

public static void main(String[] args) {

Test t = new Test();

t.myMethod(null);

}

}

4、下面代码的输出结果是什么?

package test;

public class Test {

public static void main(String[] args) {

double val = 11.5;

System.err.println(Math.round(val));

System.err.println(Math.floor(val));

System.err.println(Math.ceil(val));

}

}

5、 下面代码的结果是什么?

package test;

public class Test extends Base {

public static void main(String[] args) {

Base b = new Test();

b.method();

Test t = new Test();

t.method();

}

@Override

public void method() {

System.err.println("test");

}

}

class Base {

public void method() throws InterruptedException {

System.err.println("base");

}

}

6、以下代码的结果是什么?

package test;

public class Test extends Base {

public static void main(String[] args) {

new Test().method();

}

public void method() {

System.err.println(this.getClass().getName());

System.err.println(super.getClass().getName());

System.err.println(this.getClass().getSuperclass().getName());

System.err.println(super.getClass().getSuperclass().getName());

}

}

class Base {

}

7、true or false?

package test;

public class Test {

public static void main(String[] args) {

String str1 = new String("abc");

String str2 = new String("abc");

System.err.println(str1.equals(str2));

StringBuffer sb1 = new StringBuffer("abc");

StringBuffer sb2 = new StringBuffer("abc");

System.err.println(sb1.equals(sb2));

}

}

8、输出的结果是什么?

package test;

public class Test {

public static void main(String[] args) {

System.err.println(new Test().method1());

System.err.println(new Test().method2());

}

public int method1() {

int x = 1;

try {

return x;

} finally {

++x;

}

}

public int method2() {

int x = 1;

try {

return x;

} finally {

return ++x;

}

}

}

9、true or false?

package test;

public class Test {

public static void main(String[] args) {

System.err.println(12 - 11.9 == 0.1);

}

}

10、以下代码输出是什么?

package test;

import java.math.BigInteger;

public class Test {

public static void main(String[] args) {

BigInteger one = new BigInteger("1");

BigInteger two = new BigInteger("2");

BigInteger three = new BigInteger("3");

BigInteger sum = new BigInteger("0");

sum.add(one);

sum.add(two);

sum.add(three);

System.out.println(sum.toString());

}

}

//==================华丽的分隔线==================//

温馨提示:找工作笔试中,也许就有这样的奇葩问题。题目考的不是有多难,考的是你细不细心,对知识点的理解透彻不透彻。

以下是答案:

(1)、 System.out.printf("A") == null

(2)、

第一行结果i1 + i2 = 1010

第二行异常,字符串不能和数字做减法

第三行i1 * i2 = 100

第四行i1 / i2 = 1

(3)、尽可能的从子类找,因此是string

(4)、要注意返回类型long,double,double,答案是

12

11.0

12.0

(5)、 答:异常。因为子类重写父类方法时也要抛出异常。

(6)、

test.Test

test.Test

test.Base

test.Base

(7)、

true

false

(8)、

1

2

(9)、 false

(10)、0

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP