试题如下:
参考答案:
import java.io.FileNotFoundException;import java.io.IOException;import java.util.ArrayList;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;
/*** Created by ysc on 7/26/16.
*/ public class Interview {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) System.out.println(thread.getName()+"->"+thread.isDaemon()+" "+thread.getPriority()));System.out.println("3. gc线程是daemon线程");}private static volatile int count = 0;private static void four(){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 should be: "+10000000+", actual be: "+count);System.out.println("4. volatile不能保证线程安全");}private static void five(){ArrayList
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";change(str);System.out.println(str);}}private static class ForLoop{static boolean foo(char c){System.out.print(c);return true;}
public static void main(String[] args) {int i=0;for(foo('A');foo('B')&&(i<2);foo('C')){i++;foo('D');}System.out.println();}}private static class HelloA{public HelloA(){System.out.println("HelloA");}
{ System.out.println("I'm A class"); }
static {System.out.println("static A");}}private static class HelloB extends HelloA{public HelloB(){System.out.println("HelloB");}
{ System.out.println("I'm 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();two();three();four();five();six();seven();eight();nine();ten();Null.main(null);StringExample1.main(null);StringExample2.main(null);ForLoop.main(null);HelloB.main(null);}}以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:15个高级Java多线程面试题及回答探讨Java中最常见的十道面试题(超经典) JAVA实现链表面试题最有价值的50道java面试题 适用于准入职Java程序员Java实现栈和队列面试题关于Java集合框架面试题(含答案)下java 多态性详解及常见面试题10个经典的Java main方法面试题适用于Java程序员的10道XML面试题 新鲜出炉网易Java程序员两轮面试 请问你能答对几个?
