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

1
2
3
4
5
6
7
8
9
public static void main(String[] args) {

        if (          ){//填写条件
System.out.print("A");
} else {
System.out.print("B");
}
}
}

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

 1
2
3
4
5
6
7
8
9
10
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、下面代码的结果是什么?还是抛出异常?

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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、下面代码的输出结果是什么?

 1
2
3
4
5
6
7
8
9
10
11
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、 下面代码的结果是什么?

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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、以下代码的结果是什么?

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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?

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
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、输出的结果是什么?

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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?

1
2
3
4
5
6
7
8
package test;

public class Test {

    public static void main(String[] args) {
System.err.println(12 - 11.9 == 0.1);
}
}

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

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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

转载自:http://my.eoe.cn/zhongcx/archive/24063.html

Java奇葩笔试题的更多相关文章

  1. 非常全面的java基础笔试题

    下面是java基础笔试题,当时我去笔试,做了1个小时(80道选择题,后面的简答题就没时间做了),结果很吓人,太挫了,最后被面试官忽悠去培训去了,呵呵.我偷偷把面试题弄了下来,用来学习吧,也希望能对你们 ...

  2. Java 面试/笔试题神整理 [Java web and android]

    Java 面试/笔试题神整理 一.Java web 相关基础知识 1.面向对象的特征有哪些方面 1.抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并 ...

  3. Java工程师笔试题整理[校招篇]

    Java工程师笔试题整理[校招篇]     隔着两个月即将开始校招了.你是不是也想借着这个机会崭露头角,拿到某些大厂的offer,赢取白富美.走上人生巅峰?当然如果你还没能打下Java基础,一定要先打 ...

  4. Java基础&笔试题

    这些题目是近期我参加过的笔试题和一些我在网上选的部分题,在这里做笔记,认真去学习,更好的应对后面的招聘.有错误欢迎指出. 一.Java基础部分 1.指针在任何情况下都可进行>,<,> ...

  5. Android开发面试经——3.常见Java基础笔试题

      Android开发(29)  版权声明:本文为寻梦-finddreams原创文章,请关注:http://blog.csdn.net/finddreams 关注finddreams博客:http:/ ...

  6. [原创]Java常见笔试题知识点汇总

    前天数梦工厂来学校招聘,笔试题比较有特点,全是Java题,基本就是Java的一些特点.凭记忆按照题目找到一些必备知识点 (1). try {}里有一个return语句,那么紧跟在这个try后的fina ...

  7. 深圳市利汇电子商务科技有限公司2019年java面试笔试题

    垃圾公司,建议不要去,写的地址去了发现是两个公司公用一个办公场地,还没有公司的招牌,去了交简历给前台然后就是 填一份求职申请,一份笔试题如下,然后就等待,先是人事的一个小妹妹面试,问一些个人问题,为什 ...

  8. java面试笔试题大汇总

    第一,谈谈final, finally, finalize的区别.  最常被问到.   第二,Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以 ...

  9. 2019 奥买家java面试笔试题 (含面试题解析)

      本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.奥买家等公司offer,岗位是Java后端开发,因为发展原因最终选择去了奥买家,入职一年时间了,也成为了面试官 ...

随机推荐

  1. 【BZOJ3522&BZOJ4543】Hotel加强版(长链剖分,树形DP)

    题意:求一颗树上三点距离两两相等的三元组对数 n<=1e5 思路:From https://blog.bill.moe/bzoj4543-hotel/ f[i][j]表示以i为根的子树中距离i为 ...

  2. SQL注入的简单认识

    写在前面 MYSQL5.0之后的版本,默认在数据库中存放一个information_schema的数据库,其中应该记住里面的三个表SCHEMATA.TABLES.COLUMNS SCHEMATA表:存 ...

  3. LOJ 3058 「HNOI2019」白兔之舞——单位根反演+MTT

    题目:https://loj.ac/problem/3058 先考虑 n=1 怎么做.令 a 表示输入的 w[1][1] . \( ans_t = \sum\limits_{i=0}^{L}C_{L} ...

  4. 2018-2019-2 网络对抗技术 20165206 Exp7 网络欺诈防范

    - 2018-2019-2 网络对抗技术 20165206 Exp7 网络欺诈防范 - 实验任务 (1)简单应用SET工具建立冒名网站 (1分) (2)ettercap DNS spoof (1分) ...

  5. 深入浅出HashMap

    /** *@ author ViVi *@date 2014-6-11 */ Hashmap是一种非常常用的.应用广泛的数据类型,最近研究到相关的内容,就正好复习一下.希望通过仪器讨论.共同提高~ 1 ...

  6. SQL 批量插入数据

    后面进行完善修改. /*批量插入数据*/ 这个比较完善.直接插入数据库表. INSERT INTO `goods_transverter` ( `code`,`es_id`,`barcode`, `n ...

  7. CET-6 分频周计划生词筛选(Week 2)

    点我阅读 Week 2 2016.09.04/05 p58 ongoing / forward p59 prosperity p60 rear p61 rival + segregation + se ...

  8. subprocess 模块 与 re 模块

    sub :子 process:进程 用法: import subprocess while True: cmd_str = inport('请输入终端命令:') obj = subprocrss.Po ...

  9. Hibernate4教程二:基本配置

    可编程的配置方式一: 如果在配置cfg.xml的时候,不想在里面配置hbm.xml怎么办呢?可在程序里使用可编程的配置方式,也就是使用程序来指定在cfg.xml里面的配置信息,不推荐这种方式.如下: ...

  10. Flask-SQLAlchemy使用方法

    Flask-SQLAlchemy使用起来非常有趣,对于基本应用十分容易使用,并且对于大型项目易于扩展.有关完整的指南,请参阅 SQLAlchemy 的 API 文档. 常见情况下对于只有一个 Flas ...