欢迎来到天天文库
浏览记录
ID:51723153
大小:37.50 KB
页数:10页
时间:2020-03-15
《JAVA编程思想课后习题答案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Java编程思想(第四版)习题答案第二章练习1:publicclassPrimitiveTest{staticinti;staticcharc;publicstaticvoidmain(String[]args){System.out.println("int="+i);System.out.println("char="+c);}}练习2:publicclassHelloWorld{publicstaticvoidmain(String[]args){System.out.println("HelloWorld!");}}练习3:publicclassATN
2、Test{publicstaticvoidmain(String[]args){classATypeName{inti;doubled;booleanb;voidshow(){System.out.println(i);System.out.println(d);System.out.println(b);}}ATypeNamea=newATypeName();a.i=3;a.d=2.71828;a.b=false;a.show();}}练习4:publicclassDataOnlyTest{publicstaticvoidmain(String[]args)
3、{classDataOnly{inti;doubled;booleanb;voidshow(){System.out.println(i);System.out.println(d);System.out.println(b);}}DataOnlydata=newDataOnly();data.i=3;data.d=2.71828;data.b=false;data.show();}}练习5:publicclassDOTest2{publicstaticvoidmain(String[]args){classDataOnly{inti;doubled;bool
4、eanb;voidshow(){System.out.println(i);System.out.println(d);System.out.println(b);}}DataOnlydata=newDataOnly();data.i=234;data.d=2.1234545;data.b=true;data.show();}}练习6:publicclassStorageTest{publicstaticvoidmain(String[]args){classStoreStuff{intstorage(Strings){returns.length()*2;}
5、}StoreStuffx=newStoreStuff();System.out.println(x.storage("hi"));}}练习7:classStaticTest{staticinti=47;}classIncrementable{staticvoidincrement(){StaticTest.i++;}}publicclassITest{publicstaticvoidmain(String[]args){System.out.println("StaticTest.i="+StaticTest.i);StaticTestst1=newStati
6、cTest();StaticTestst2=newStaticTest();System.out.println("st1.i="+st1.i);System.out.println("st2.i="+st2.i);Incrementablesf=newIncrementable();sf.increment();System.out.println("Aftersf.increment()called:");System.out.println("st1.i="+st1.i);System.out.println("st2.i="+st2.i);Increm
7、entable.increment();System.out.println("AfterIncrementable.incrementcalled:");System.out.println("st1.i="+st1.i);System.out.println("st2.i="+st2.i);}}练习8:classStaticTest{staticinti=47;}classIncrementable{staticvoidincrement(){StaticTest.i++;}}publicclassOneStaticTest{publicstaticvoi
8、dmain(String[]args)
此文档下载收益归作者所有