资源描述:
《java练习题培训资料.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、__________________________________________________1.以下字符常量中不符合语法规则的是________。A.'*'B.'''C.""D.'大'2.以下所列符号中可做标识符的是________。A.%abcB.$abcC.2abcD.true3.若要定义一个不可被继承的类,在类定义的头部应使用修饰词________。A.abstractB.protectC.publicD.final4.下列选项中正确的方法定义是________。A.intx(inta
2、,b){returna-b;}B.intx(inta,intb){intw;w=a-b;}C.doublex(a,b){returnb;}D.doublex(inta,intb){returna-b;}5.执行下列程序段后,m,x,y的值分别为________。intx=2,y=4;booleanm;m=++x>y--;A.true,2,4B.false,2,4C.true,3,3D.false,3,36.__________________________________________________
3、__________________________________________________对于本题程序,以下关于编译、运行情况的叙述正确的是________。publicclassJ0728f{finalintx=0;publicJ0728f(){x=12;System.out.println(x%10);}publicstaticvoidmain(Stringargs[]){J0728fj=newJ0728f();}}A.编译出错,因试图改变常量的值B.编译通过,运行期间出现异常C.编译和运行
4、正常,输出1D.编译和运行正常,输出27.本题程序段运行后产生的输出是________。intx=0;outer:while(true){x++;inner:for(inty=0;y<10;y++){x+=y;if(y==3)continueinner;breakouter;____________________________________________________________________________________________________}continueouter;}S
5、ystem.out.println(x);8.本题程序运行后输出的第一行是__________,第二行是__________。classSuperClass{inta,b;SuperClass(intaa,intbb){a=aa;b=bb;}voidshow(){System.out.println("a="+a+"b="+b);}}classSubClassextendsSuperClass{intc;SubClass(intaa,intbb,intcc){super(aa,bb);c=cc;}}cla
6、ssSubSubClassextendsSubClass{____________________________________________________________________________________________________inta;SubSubClass(intaa,intbb,intcc){super(aa,bb,cc);a=aa+bb+cc;}voidshow(){System.out.println("a="+a+"b="+b+",c="+c);}}publi
7、cclasstest{publicstaticvoidmain(String[]args){SubSubClassx=newSubSubClass(7,8,9);x.show();}}9.本题程序中的方法fa(longn)用递归算法求非零自然数n的阶乘。填充程序中的空格,使本程序计算5的阶乘并输出其值。publicclasstest{__________fa(longn){if(n==1)return1;___________________________________________________
8、_________________________________________________elsereturn__________;}publicstaticvoidmain(String[]args){longresult=__________;System.out.println(result);}}10.以下选项中可正确声明一个整型变量的是________。A.int$x;B.int123;C.int#div;D