13常用类3.1单项选择题1.设有下面两个赋值语句:a=Integer.parseInt(“12”);b=Integer.valueOf(“12”).intValue();下述说法正确的是()。A.a是整数类型变量,b是整数类对象。B.a是整数类对象,b是整数类型变量。C.a和b都是整数类对象并且值相等。D.a和b都是整数类型变量并且值相等。2.关于以下代码段的说法正确的是()1.Strings=abcde;2.StringBuffers1=newStringBuffer(abcde);3.if(s.equals(s1))4.s1=null;5.if(s1.equals(s))6.s=null;A.第1行编译错误,String的构造器必须明确调用B.第3行编译错误,因为s与s1有不同的类型C.编译成功,但执行时在第5行有异常抛出D.编译成功,过程中也没有异常抛出3.已知如下定义:Strings=story;下面哪个语句不是合法的()A.s+=books;B.s=s+100;C.intlen=s.length;D.Stringt=s+“abc”;4.下列程序段执行后的结果是()。Strings=newString(abcdefg);for(inti=0;is.length();i+=2){System.out.print(s.charAt(i));}A.acegB.ACEGC.abcdefgD.abcd5.有整型数组:int[]x={12,35,8,7,2};,则调用方法Arrays.sort(x)后,数组x中的元素值依次是().A.2781235B.1235872C.3512872D.87123526.应用程序的main方法中有以下语句,则输出的结果是()。Strings1=newString(abc);Strings2=newString(abc);booleanb1=s1.equals(s2);2booleanb2=(s1==s2);System.out.print(b1++b2);A.truefalseB.falsetrueC.truetrueD.falsefalse7.应用程序的main方法中有以下语句,则输出的结果是()。Strings=12345#aaa#bbb#67890;intn=s.indexOf(#);intk=s.indexOf(#,n+1);intm=s.indexOf(#,k+1);Strings2=s.substring(m+1);System.out.println(s2);A.123456B.67890C.aaaD.bbb8.应用程序的main方法中有以下语句,则输出的结果是()。Strings=xxxxxxxxxxxxxxx#123#456#zzzzz;intn=s.indexOf(#);intk=s.indexOf(#,n+1);Strings2=s.substring(n+1,k);System.out.println(s2);A)123456B)123C)xxxxxxxxxxxxxxxD)zzzzz9.请说出下列代码的执行结果:Strings=abcd;Strings1=newString(s);if(s==s1)System.out.println(thesame);if(s.equals(s1))System.out.println(equals);A.thesameequalsB.equalsC.thesameD.什么结果都不输出3.2简答题1.String和StringBuffer的区别?3.3程序阅读题1.阅读以下程序,写出输出结果。classAnimal{Animal(){System.out.print(Animal);}}publicclassDogextendsAnimal{Dog(){3System.out.print(Dog);}publicstaticvoidmain(String[]args){Dogsnoppy=newDog();}}2、以下程序的输出结果为_____。publicclassCourse{privateStringcNumber;privateStringcName;privateintcUnit;publicCourse(Stringnumber,Stringname,intunit){cNumber=number;cName=name;cUnit=unit;}publicvoidprintCourseInfo(){System.out.println(课程号:+cNumber+课程名:+cName+学分:+cUnit);}}classCourseTest{publicstaticvoidmain(String[]args){Coursec;c=newCourse(101,ASP,3);c.printCourseInfo();}}3、以下程序的输出结果为_____。publicclassTom{privatefloatweight;privatestaticStringname;publicvoidsetWeight(floatweight){this.weight=weight;}privatevoidout(){System.out.println(name+体重:+weight+斤);4}publicstaticvoidmain(String[]args){Tom.name=汤姆猫;Tomcat=newTom();cat.setWeight(20);cat.out();}}4、以下程序的输出结果__。publicclassFather{Stringname,address,tel;intage;publicFather(Stringname,intage){this.name=name;this.age=age;}voidout(){System.out.print(姓名:+name);System.out.print(年龄:+age);}voidoutOther(){System.out.print(家庭住址:+address);System.out.print(电话:+tel);}}classSonextendsFather{Stringschool;publicSon(Stringname,intage){super(name,age);}voidout(){super.out();super.outOther();System.out.println(学校:+school);}5publicstaticvoidmain(Stringargs[]){Sonson=newSon(Tom,15);son.address=中关村;son.school=八中;son.tel=66123456;son.out();}}5、下列程序的运行结果是______。publicclassMyClass{inta[]={1,2,3,4,5};voidout(){for(intj=0;ja.length;j++)System.out.print(a[j]+);}publicstaticvoidmain(String[]args){MyClassmy=newMyClass();my.out();}}6.写出下面的程序编译、运行后的结果(6分)。publicclassTest{publicstaticvoidmain(Stringargs[]){newStudent(Tom,'m',90,88);newStudent(Jack,'m',66,89);newStudent(Mary,'f',76,86);System.out.println(name\tsex\tchinese\tenglish);Student.print();}}classStudent{protectedStringname;protectedcharsex;protectedintchinese;protectedintenglish;protectedStudentnext;staticStudentlist;Student(Stringname,charsex,intchinese,intenglish){6this.name=name;this.sex=sex;this.chinese=chinese;this.english=english;this.next=list;list=this;}staticvoidprint(){Studentfriend=list;if(friend==null)System.out.println(Thelistisempty.);else{do{System.out.println(friend.toString());friend=friend.next;}while(friend!=null);}}publicStringtoString(){returnnewString(name+\t+sex+\t+chinese+\t+english);}}7.阅读程序,给出结果://AbstractClassDemo.java源代码如下:abstractclassShape{//定义抽象类Shape和抽象方法displayabstractvoiddisplay();}classCircleextendsShape{voiddisplay(){//实现抽象类的方法System.out.println(Circle);}}classRectangleextendsShape{voiddisplay(){//实现抽象类的方法System.out.println(Rectangle);}}classTriangleextendsShape{voiddisplay(){//实现抽象类的方法System.out.println(Triangle);}}publicclassAbstractClassDemo{publicstaticvoidmain(Stringargs[]){7(newCircle()).display();//定义无名对象来调用对应的display方法(newRectangle()).display();(newTriangle()).display();}}输出结果是?8.按要求填空abstractclassSuperAbstract{voida(){…}abstractvoidb();abstractintc(inti);}interfaceAsSuper{voidx();}abstractclassSubAbstractextendsSuperAbstractimplementsAsSuper{publicvoidb(){…}abstractStringf();}publicclassInheritAbstractextendsSubAbstract{publicvoidx(){…}publicintc(inti){…}publicStringf(){…}publicstaticvoidmain(Stringargs[]){InheritAbstractinstance=newInheritAbstract();instance.x();instance.a();instance.b();instance.c(100);System.out.println(instance.f());}}在以上这段程序中:抽象类有:SuperAbstract和(1)(写出类名)非抽象类有:(2)(写出类名)接口有:(3)(写出接口名)AsSuper中的x()方法是(4)方法,所以在InheritAbstract中必须对它进行(5)9.publicclassSum{publicstaticvoidmain(String[]args){intj=10;System.out.println(jis:+j);calculate(j)