试题如下:
参考答案:
นำเข้า java.io.filenotfoundexception; นำเข้า java.io.ioexception; นำเข้า java.util.arraylist; นำเข้า java.util.concurrent.executorservice; นำเข้า java.util.concurrent.executors;/*** สร้างโดย YSC ใน 7/26/16 */การสัมภาษณ์ระดับสาธารณะ {โมฆะคงที่ส่วนตัวหนึ่ง () {String str1 = "Hello"; string str2 = "เขา"+สตริงใหม่ ("llo"); System.err.println (str1 == str2); System.out.println ("1. false"); } โมฆะคงที่ส่วนตัวสอง () {int i = integer.max_value; System.err.println ((i+1) <i); System.out.println ("2. 存在一个 i, 使得 (i+1) <i"); } โมฆะคงที่ส่วนตัวสาม () {System.err.println ("GC ไม่ใช่เธรด Java มันเป็นเธรดดั้งเดิม"); thread.getAllStackTraces (). keyset (). foreach (เธรด -> system.out.println (thread.getName ()+" ->"+thread.isdaemon ()+""+thread.getPriority ())); System.out.println ("3. GC 线程是 Daemon 线程"); } การนับจำนวน int ผันผวนแบบคงที่ส่วนตัว = 0; โมฆะคงที่ส่วนตัวสี่ () {ExecutorService ExecutorService = Executors.newCachedThreadPool (); สำหรับ (int j = 0; j <10; j ++) {executorService.submit (()-> {สำหรับ (int i = 0; i <1000000; i ++) {count ++;}}); } system.out.println ("นับควรเป็น:" +10000000+ ", จริง be:"+count); System.out.println ("4. ผันผวน不能保证线程安全"); } ส่วนตัวคงที่เป็นโมฆะห้า () {arrayList <integer> list = new ArrayList <> (20); list.add (1); System.out.println ("รหัสการดีบักไม่ใช่วิธีการเติบโต"); System.out.println ("5. รายการเติบโต 0 ครั้ง"); } โมฆะคงที่ส่วนตัวหก () {system.out.println ("ตัวสร้างของบัฟเฟอร์รีดเดอร์ยอมรับอินสแตนซ์ผู้อ่านเท่านั้น"); System.out.println ("6. BufferedReader ใหม่ (ใหม่ FileInputStream (/" A.Dat/")); ผิด"); } โมฆะคงที่ส่วนตัวเจ็ด () {ลอง {ถ้า (จริง) {โยน iOexception ใหม่ (); }} catch (filenotfoundexception e) {system.out.print ("filenotfoundexception!"); } catch (ioexception e) {system.out.print ("ioexception!"); } catch (exception e) {system.out.print ("Exception!"); } system.out.println ("/n7. ioexception!"); } โมฆะคงที่ส่วนตัวแปด () {System.out.println ("String s; system.out.println (s); ข้อผิดพลาด: ตัวแปร s อาจไม่ได้เริ่มต้น/nrecompile ด้วย -xlint: ไม่ถูกตรวจสอบรายละเอียด"); System.out.println ("8. 由于สตริง s 没有初始化, 代码不能编译通过"); } โมฆะคงที่ส่วนตัวเก้า () {system.out.println ("5" +2); System.out.println ("9. 52"); } โมฆะคงที่ส่วนตัวสิบ () {int i = 2; int result = 0; สวิตช์ (i) {กรณีที่ 1: ผลลัพธ์ = ผลลัพธ์ + i; กรณีที่ 2: ผลลัพธ์ = ผลลัพธ์ + i * 2; กรณีที่ 3: ผลลัพธ์ = ผลลัพธ์ + i * 3; } system.out.println ("result ="+ผลลัพธ์); System.out.println ("10. 10"); } คลาสคงที่คลาสคงที่ null {โมฆะคงที่สาธารณะ hello () {system.out.println ("สวัสดี"); } โมฆะคงที่สาธารณะหลัก (สตริง [] args) {((null) null) .hello (); null _null = (null) null; _null.hello (); }} คลาสคงที่คลาสคงที่ stringExample1 {string str = สตริงใหม่ ("ดี"); char [] ch = {'a', 'b', 'c'}; การเปลี่ยนแปลงโมฆะสาธารณะ (สตริง str, char [] ch) {str = "ทดสอบตกลง"; ch [0] = 'g'; } โมฆะคงที่สาธารณะหลัก (สตริง [] args) {stringExample1 ex = ใหม่ stringExample1 (); Ex.Change (Ex.str, Ex.ch); System.out.print (ex.str+"และ"); System.out.print (Ex.ch); System.out.println (); }} คลาสคงที่คลาสคงที่ stringExample2 {การเปลี่ยนแปลงโมฆะคงที่สาธารณะ (String str) {str = "ยินดีต้อนรับ"; } โมฆะคงที่สาธารณะหลัก (สตริง [] args) {string str = "1234"; เปลี่ยน (str); System.out.println (str); }} คลาสคงที่ส่วนตัว forloop {boolean foo แบบคงที่ (ถ่าน C) {System.out.print (C); กลับมาจริง; } โมฆะคงที่สาธารณะหลัก (สตริง [] args) {int i = 0; สำหรับ (foo ('a'); foo ('b') && (i <2); foo ('c')) {i ++; อาหาร'); } system.out.println (); }} คลาสคงที่ส่วนตัว helloa {public helloa () {system.out.println ("helloa"); } {system.out.println ("ฉันเป็นคลาส"); } คงที่ {System.out.println ("Static A"); }} ชั้นเรียนคงที่ส่วนตัว hellob ขยาย helloa {public hellob () {system.out.println ("hellob"); } {System.out.println ("I'm B class"); } คงที่ {System.out.println ("Static B"); } โมฆะคงที่สาธารณะหลัก (สตริง [] args) {system.out.println ("เริ่มต้นหลัก"); ใหม่ hellob (); ใหม่ hellob (); System.out.println ("Main End"); }} โมฆะคงที่สาธารณะหลัก (สตริง [] args) {one (); สอง(); สาม(); สี่ (); ห้า(); หก(); เจ็ด (); แปด(); เก้า(); สิบ(); null.main (null); StringExample1.Main (NULL); StringExample2.Main (NULL); forloop.main (null); hellob.main (Null); -以上就是本文的全部内容, 希望对大家的学习有所帮助, 也希望大家多多支持武林网。