欢迎来到天天文库
浏览记录
ID:32585431
大小:73.63 KB
页数:12页
时间:2019-02-13
《java开发工程师面试题整合-程序题》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1:设计4个线程,其中两个线程每次对j增加1,另外两个线程对j每次减少1。写出程序。以下程序使用内部类实现线程,对j增减的时候没有考虑顺序问题。publicclassThreadTest1{privateintj;publicstaticvoidmain(Stringargs[]){Threadiest1tt二newThreadTest1();Incinc=tt.newInc();Decdec=tt.newDec();for(inti=0;i<2;i++){Threadt二newThread(inc);t・st
2、art();t=newThread(dec);t・start();privatesynchroni/edvoidinc(){j++;System,out.printin(Thread.currentThread().getName()+"-inc:〃+j);}privatesynchroni/edvoiddec(){j--;System,out.printin(Thread,currentThread().getName()+〃-dec:〃+j);}classIncimp1ernentsRunnable{pub
3、licvoidrun(){for(inti=0;i<100;i++){inc();classDecimplementsRunnable{publicvoidrun(){for(inti二0;i<100;i++){dec();2:打印结果System.out.println(l+' 02,)会打印出多少?_3System.out.println(1+2+”3")会打印出多少?_333:要求最后打印出的全部是数字,下面的程序满足要求吗?还可以再优化吗?请简单描述。StringstrA二“1:2:3:4:5:6:7
4、:8:9:10:";StringarrAfl=sU*A.split('':");for(inti=0;i5、t.FatherClass;publicclassChildClassextendsFatherClass{publicChildClass(){System,out.printinC'ChildClassCreate");}publicstaticvoidmain(String[]args){FatherClassfc=newFatherClass();ChildClasscc=newChildClass();}}答:输出结果:C:>javatest.ChildClassFatherClassCreateFa6、therClassCreateChildClassCreate5:内部类的实现方式?答:示例代码如下:packagetest;publicclassOuterClass{privateclassTnterClass{publicInterClass(){System.out.printin("InterClassCreate");}}publicOuterClass(){TnterClassic=newInterClass();System,out.printIn("'OuterClassCreate");}p7、ublicstaticvoidmain(String[]args){OuterClassoc=newOuterClass();}}输出结果:C:>javatest/OuterClassTnterClassCreateOuterClassCreate6:例题publicclassOuterClass{privatedoubledl=1.0;//insertcodehere}Youneedtoinsertaninnerclassdeclarationatline3・Whichtwoinnerclassdeclara8、tionsarevalid?(Choosetwo.)A.classInnerOne{publicstaticdoublemethodaO{returndl;}}B・publicclassInnorOne{staticdoublemethodaO{returndl;}}C.privateclassTnnerOne{doublemethodaO{returndl;}}D.staticcla
5、t.FatherClass;publicclassChildClassextendsFatherClass{publicChildClass(){System,out.printinC'ChildClassCreate");}publicstaticvoidmain(String[]args){FatherClassfc=newFatherClass();ChildClasscc=newChildClass();}}答:输出结果:C:>javatest.ChildClassFatherClassCreateFa
6、therClassCreateChildClassCreate5:内部类的实现方式?答:示例代码如下:packagetest;publicclassOuterClass{privateclassTnterClass{publicInterClass(){System.out.printin("InterClassCreate");}}publicOuterClass(){TnterClassic=newInterClass();System,out.printIn("'OuterClassCreate");}p
7、ublicstaticvoidmain(String[]args){OuterClassoc=newOuterClass();}}输出结果:C:>javatest/OuterClassTnterClassCreateOuterClassCreate6:例题publicclassOuterClass{privatedoubledl=1.0;//insertcodehere}Youneedtoinsertaninnerclassdeclarationatline3・Whichtwoinnerclassdeclara
8、tionsarevalid?(Choosetwo.)A.classInnerOne{publicstaticdoublemethodaO{returndl;}}B・publicclassInnorOne{staticdoublemethodaO{returndl;}}C.privateclassTnnerOne{doublemethodaO{returndl;}}D.staticcla
此文档下载收益归作者所有