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. spring+cxf

    里面有http://127.0.0.1:8081/dcs/soap/cls       http://127.0.0.1:8081/dcs/soap/cms       http://127.0.0. ...

  2. Buuctf | sqli-labs

    这个是赵师傅给我们提供的训练靶场,最好都打一遍,但是出于找flag的角度,特此记录一下,flag在哪里[没错,我就是喜欢我的蓝变红,哈] ?id=1' :报错,说明就是用这个闭合的 ?id=0' un ...

  3. element upload上传前对文件专门bs64上传

    <!-- 文件上传 --> <template> <section class="file-upload"> <p class=" ...

  4. C++ 指针基址1

    char *p=(char *)&n;中括号中为什幺要加个*号 答: &n是一个整型数值,代表变量n的地址,不包含其所保存的数据的类型信息(也就是说只凭借一个地址是不能推测出,该地址所 ...

  5. 在RedHat中安装新字体

    安装 下载这个字体. http://pan.baidu.com/s/1c23znaS 密码:tldo 在/usr/share/fonts/truetype/, 下建立一个新的目录 YaHei Cons ...

  6. js不同类型作比较

    引用自 http://www.zhufengpeixun.cn/jishuziliao/javaScriptzhuanti/2014-06-14/300.html 不同类型间的比较,规律如下 类型 类 ...

  7. ubuntu snap 包管理器

    基本使用 snap find $package snap install $package [--channel=beta] snap list snap refresh $package [--ch ...

  8. Git SSH连接方式配置

    如果使用ssh的方式管理,需要配置ssh key. 1.打开git bash命令窗口 2.生成ssh key ssh-keygen -t rsa -b 4096 -C "your_email ...

  9. uWSGI、WSGI、uwsgi、wsgiref、werkzeug

    WSGI WSGI:全称是Web Server Gateway Interface,WSGI不是服务器,也不是python模块.框架.API或者任何软件,只是一种规范,描述web server如何与w ...

  10. BUUCTF Youngter-drive

    exe逆向,首先查壳,发现有upx壳,upx -d脱壳,拖进ida找到主函数这里可以看到创建了两个线程,先沿着StartAddress,一直找到sub_411940,这里有一个问题,当使用f5是,会显 ...