欢迎来到天天文库
浏览记录
ID:37971454
大小:21.79 KB
页数:13页
时间:2019-06-04
《《JAVA程序设计》(习题)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、《JAVA程序设计》练习题写出下面程序的运行结果1、importjava.io.*;publicclassabc{publicstaticvoidmain(Stringargs[]){ABs=newAB("Hello!","IloveJAVA.");System.out.println(s.toString());}}classAB{Strings1;Strings2;publicAB(Stringstr1,Stringstr2){s1=str1;s2=str2;}publicStringtoString(){return
2、s1+s2;}}运行结果:Hello!IloveJAVA2、importjava.io.*;publicclassabc{publicstaticvoidmain(Stringargs[]){inti,s=0;inta[]={10,20,30,40,50,60,70,80,90};for(i=0;i3、ublicstaticvoidmain(Stringargs[]){System.out.println("a="+a+"b="+b);}}classSubClassextendsSuperClass{intc;SubClass(intaa,intbb,intcc){super(aa,bb);c=cc;}}classSubSubClassextendsSubClass{inta;SubSubClass(intaa,intbb,intcc){super(aa,bb,cc);A=aa+bb+cc;}voidshow(){S4、ystem.out.println("a="+a+"b="+b+"c="+c);}}运行结果:a=60b=20c=304、以下程序的输出结果为_Peteris17yearsold!________________。publicclassPerson{Stringname;intage;publicPerson(Stringname,intage){this.name=name;this.age=age;}publicstaticvoidmain(String[]args){Personc=newPerson("Pe5、ter",17);System.out.println(c.name+"is"+c.age+"yearsold!");}}5、以下程序的输出结果为__课程号:101课程名:ASP学分:3___________________。publicclassCourse{privateStringcNumber;privateStringcName;privateintcUnit;publicCourse(Stringnumber,Stringname,intunit){cNumber=number;cName=name;cUnit6、=unit;}publicvoidprintCourseInfo(){System.out.println("课程号:"+cNumber+"课程名:"+cName+"学分:"+cUnit);}}classCourseTest{publicstaticvoidmain(String[]args){Coursec;c=newCourse("101","ASP",3);c.printCourseInfo();}}6、以下程序的输出结果为__汤姆猫体重:20.0斤___________________。publicclassTom7、{privatefloatweight;privatestaticStringname;publicvoidsetWeight(floatweight){this.weight=weight;}privatevoidout(){System.out.println(name+"体重:"+weight+"斤");}publicstaticvoidmain(String[]args){Tom.name="汤姆猫";Tomcat=newTom();cat.setWeight(20);cat.out();}}7、以下程序的输出结果8、_姓名:Tom年龄:15家庭住址:金水区电话:_66123456学校:九中_______________。publicclassFather{Stringname,address,tel;intage;publicFather(Stringname,intage){this.name=name;this
3、ublicstaticvoidmain(Stringargs[]){System.out.println("a="+a+"b="+b);}}classSubClassextendsSuperClass{intc;SubClass(intaa,intbb,intcc){super(aa,bb);c=cc;}}classSubSubClassextendsSubClass{inta;SubSubClass(intaa,intbb,intcc){super(aa,bb,cc);A=aa+bb+cc;}voidshow(){S
4、ystem.out.println("a="+a+"b="+b+"c="+c);}}运行结果:a=60b=20c=304、以下程序的输出结果为_Peteris17yearsold!________________。publicclassPerson{Stringname;intage;publicPerson(Stringname,intage){this.name=name;this.age=age;}publicstaticvoidmain(String[]args){Personc=newPerson("Pe
5、ter",17);System.out.println(c.name+"is"+c.age+"yearsold!");}}5、以下程序的输出结果为__课程号:101课程名:ASP学分:3___________________。publicclassCourse{privateStringcNumber;privateStringcName;privateintcUnit;publicCourse(Stringnumber,Stringname,intunit){cNumber=number;cName=name;cUnit
6、=unit;}publicvoidprintCourseInfo(){System.out.println("课程号:"+cNumber+"课程名:"+cName+"学分:"+cUnit);}}classCourseTest{publicstaticvoidmain(String[]args){Coursec;c=newCourse("101","ASP",3);c.printCourseInfo();}}6、以下程序的输出结果为__汤姆猫体重:20.0斤___________________。publicclassTom
7、{privatefloatweight;privatestaticStringname;publicvoidsetWeight(floatweight){this.weight=weight;}privatevoidout(){System.out.println(name+"体重:"+weight+"斤");}publicstaticvoidmain(String[]args){Tom.name="汤姆猫";Tomcat=newTom();cat.setWeight(20);cat.out();}}7、以下程序的输出结果
8、_姓名:Tom年龄:15家庭住址:金水区电话:_66123456学校:九中_______________。publicclassFather{Stringname,address,tel;intage;publicFather(Stringname,intage){this.name=name;this
此文档下载收益归作者所有