试题如下:
参考答案:
java.io.filenotfoundexception; import java.io.ioexception; Import java.util.arraylist; import java.util.current.executorservice; Import java.util.concurrent.executors;/*** 7/26/16にYSCによって作成されました。 */public classインタビュー{private static void one(){string str1 = "hello"; string str2 = "he"+new String( "llo"); System.err.println(str1 == str2); System.out.println( "1。false"); } private static void two(){int i = integer.max_value; System.err.println((i+1)<i); system.out.println( "2。存在一个i、使得(i+1)<i"); } private static void 3(){system.err.println( "gcはjavaスレッドではなく、ネイティブスレッドです"); thread.getAllStackTraces()。keyset()。 System.out.println( "3。gc线程是daemon"); } private static volatile int count = 0; private static void 4(){executorservice executorservice = executors.newcachedthreadpool(); for(int j = 0; j <10; j ++){executorservice.submit(() - > {for(int i = 0; i <1000000; i ++){count ++;}}); } system.out.println( "count be:" +10000000+ "、実際のbe:"+count); System.out.println( "4。VOLATILE不能保证线程安全"); } private static void 5(){arraylist <integer> list = new ArrayList <>(20); list.add(1); system.out.println( "デバッグコード、growメソッドを実行しない"); system.out.println( "5。listGrogure 0回数"); } private static void 6(){system.out.println( "bufferedreaderのコンストラクターは、読者インスタンスのみを受け入れる"); system.out.println( "6。NEWBUFFEREDREADER(new FileInputStream(/" a.dat/")); is誤解"); } private static void seven(){try {if(true){throw new 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!"); } private static void 8(){system.out.println( "string s; system.out.print.println(s); error:variable sは、初期化されていない/necompileが-xlint:un checked for reculy。"); System.out.println( "8。由于strings没有初始化、代码不能编译通过"); } private static void nine(){system.out.println( "5" +2); System.out.println( "9。52"); } private static void ten(){int i = 2; int result = 0; switch(i){case 1:result = result + i;ケース2:結果=結果 + i * 2;ケース3:結果=結果 + i * 3; } system.out.println( "result ="+result); System.out.println( "10。10"); } private static class null {public static void hello(){system.out.println( "hello"); } public static void main(string [] args){((null)null).hello(); null _null =(null)null; _null.hello(); }} private static class stringexample1 {string str = new String( "good"); char [] ch = {'a'、 'b'、 'c'}; public void change(string str、char [] ch){str = "test ok"; ch [0] = 'g'; } public static void main(string [] args){stringexample1 ex = new StringExample1(); Ex.Change(Ex.Str、Ex.Ch); System.out.print(ex.str+"and"); System.out.print(ex.ch); System.out.println(); }} private static class stringexample2 {public static void change(string str){str = "welcome"; } public static void main(string [] args){string str = "1234";変更(str); System.out.println(str); }} private static class forloop {static boolean foo(char c){system.out.print(c); trueを返します。 } public static void main(string [] args){int i = 0; for(foo( 'a'); foo( 'b')&&(i <2); foo( 'c')){i ++;食べ物'); } system.out.println(); }} private static class helloa {public helloa(){system.out.println( "helloa"); } {system.out.println( "私はクラスです"); } static {system.out.println( "static a"); }} private static class hellobはhelloa {public hellob(){system.out.println( "hellob"); } {system.out.println( "im b class"); } static {system.out.println( "static b"); } public static void main(string [] args){system.out.println( "main start"); new Hellob(); new Hellob(); System.out.println( "Main End"); }} public static void main(string [] args){one();二();三つ(); 4();五();六();セブン();八();九(); ten(); null.main(null); stringexample1.main(null); stringexample2.main(null); forloop.main(null); hellob.main(null); }}以上就是本文的全部内容、希望对大家的学习有所帮助、也希望大家多多支持武林网。