日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java奇葩笔试题

發布時間:2025/5/22 java 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java奇葩笔试题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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、 運算符問題,下面代碼分別輸出什么?

123456789 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、下面代碼的結果是什么?還是拋出異常?

123456789 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、下面代碼的輸出結果是什么?

123456789 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、 下面代碼的結果是什么?

123456789 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();}@Overridepublic void method() {System.err.println("test");}}class Base {public void method() throws InterruptedException {System.err.println("base");} }

6、以下代碼的結果是什么?

123456789 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?

123456789 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、輸出的結果是什么?

123456789 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、以下代碼輸出是什么?

123456789 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

轉載于:https://www.cnblogs.com/zsw-1993/p/4879456.html

總結

以上是生活随笔為你收集整理的Java奇葩笔试题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。