1、(2)&(3)|(4)| (5)选项(2),(4)均正确。练习07:请问,以下哪些语句无编译错误?(1) int testValue=0x5;(2) int testValue=(int)(2.1F+3.4D);(3) int testValue=(0x0A1);(4) int testValauc=(0x0A(5) 以上选项均正确。练习08:请问,现有一组int MyArray=1,2,3,以下哪些语句用于获取该数组的元素个数?(1) MyArray.size;(2) MyArray.siae();(3) MyArray.length;(4) MyArray.length();(5) MyA
2、rray.getSize();练习09:请问,以下哪些语句用于声明一个二维数组?(1) int a=new int10,10;(2) int a=new int 1010;(3) int a10,10=new int1010;(4) int a=new int 1010;(5) 选项(2)、(4)均正确。练习10:请问,如何强制垃圾回收器回收一个对象?(1) 调用System.gc()方法(2) 调用Runtime.gc()方法(3)将对象赋值null。(4)无法强制垃圾回收器执行。 答(4) 练习11:请问,带符号基本数据类型的正确取值范围和负数绝对取值范围是否相等?(1) 相等。(2) 不
3、相等。答(2) 练习12:请问,以下哪些是JAVA中合法的标识符?箐选择所有正确答案:(1) Big()1LongStringWithMeaniglessName(2) Sint(3) bytes(4) $1(5) finalist答(1)(2)(3)(4)(5)练习13:请问,以下哪些是应用程序的入口程序main()方法的正确语法形式?请选择所有正确答案:(1) public static void main()(2) public static void main(String arg)(3) public void main(Stringarg)(4) public static voi
4、d main(Stringargs)(5) public static int main(Stringarg)答(2)(4)练习14:请问,以下哪些Java源文件中顶层元素出现次序?(1) import,package,class.(2) classe import,package.(3) package语句必须位于最前面,import语句和class声明之间无次序要求。(4) package,import,class(5) import语句必须位于最前面,package语句和class声明之间无次序要求。 练习15:请问,执行intx=new int25;语句后,以下哪些选项正确?(1) x
5、24值等于0。(2) x24值未确定。(3) x25值等于0(4) x25值等于null。(5) x.length值等于25。答(1)(5)练习16:给出以下代码,请问该程序的运行结果是什么?1. chass Check2. public static void main(String args)3. Holder h=new Holder();4. h.held=100;5. h.bump(h);6. System.out.println(h.held);7. 8. .9. .10. class Holder11. public int held;12. theHolder.held+;13
6、. 14. 请选择一个正确答案:(1) 打印输出0(2) 打印输出1(3) 打印输出100(4) 打印输出101练习17:给以下代码,请问该程序的运行结果是什么?class Checkpublic static void main(String args)double d =12.3;Decrementer dec =new Decrementer();dec.decrement(d);System.out.println(d);class Decrementerpublic void decrement(double decMe)decMe=decMe-1.0;(1) 打印输出0。(2) 打
7、印输出-1。(3) 打印输出12。3(4) 打印输出11。练习18:(1) 无法强制垃圾回收器执行。(2) 调用System.gc()方法。(3) 调用System.gc()方法。(4) 调用Runtime.gc()方法。(5) 将对象赋值null.答(1)练习19:请问,以下哪些是短型数据的取值范围?(1) 取决于硬件环境:(2) 0.215-1(3) 0.232-1(4) -(215).215-1(5) -231.231-1练习20:请问,以下哪些是byte型数据的取值范围?(1) 取决于硬件环境。(2) 0.28-1(3) 0.215-1(4) -27.27-1(5) -215.215-
8、1练习21:Public static void main(String args)Int x,a=6,b=7;X=a+ +b+;System.out.print(“x=”+x);System.out.print(“,a=”+a);System.out.print(“,b=”+b);(1) 打印输出x=15,a=7,b=8(2) 打印输出x=15,a=6,b=7(3) 打印输出x=13,a=7,b=8(4) 打印输出x=13,a=6,b=7练习22:请问,以下哪些表达式的结果是合法的?(1) int x=6;x=!x(2) int x=6;if(!(x3)(3) int x=6;x=x;答(2
9、)(3)练习23:请问,以下哪些表达式的结果是一个整数值?(1) int x=-1;x=x5;(2) int x=-1;32;(3) byte x=-1;(4) int x=-1;练习24:请问,以下哪些表达式是合法的?请选择正确答案:(1) String x=”Hello”;int y=9;x+=y;(2) String x=”Hello”;if(x=y)(3) String x=”Hello”;x=x+y(4) String x=”Hello”;y=y+x(5) Stringx=null;int y=(x!=null)&(x.length()0)?x.length():0;答(1)(3)(
10、5)练习25:请问,以下哪些代码可编译通过且可以打印输出Equal?(1) int x=100; float y=100.0F; if(x=y) System.out.println(“Equal”); (2) Integer y=new Integer(100);(3) Integer x=new Integer(100);if(x=y) System.out.println(“Epual”);(4) public static void main(String args)String x=new String(“100”);String y=new String(“100”);If(x=y
11、)(5) public static viod main(String atgs)If(x=y) System.out.println(“Equal”);练习26:给出以下代码,请问该程序运行的结果是什么?1.public class Check2. public static viod main(String atgs)3.StingBuffer s=new StringBuffer(“Hello”);4.if(s.length)5)&5.(s.append(“there”).equals(“False”);6./do nothing7.System.out.println(“value”+
12、s)8.9.请选择一个正确的答案:(1)打印输出 value is Hello(2)打印输出 value is Hello there(3)4、5行代码编译错误。(4)无内容打印输出。(5)运行期一个NullPointerException异常抛出。练习27:public class Checkbyte b=10;byte c=15;b=(byte)(bc);System.out.println(“b contains”+s);(1) 打印输出b contains10(2) 打印输出b contains5(3) 打印输出b contains250(4) 打印输出b contains245练习2
13、8:int x=4;System.out.println(“value is”+(x4)?99.99:9)(1) 打印输出value is99.99(2) 打印输出value is9(3) 打印输出value is9.0(4) 第5行代码编译错误。练习29:int x=3;int y=10;System.out.println(y%x); (3) 打印输出2(4) 打印输出3练习30: public static void main(String args)int x=1;String names=“A”,”B”,”C”;names-x+=”,”;for(int i=0;inames,leng
14、th;i+) System.out.print(namesi);(1) 打印输出A.BC(2) 打印输出AB.C(3) 打印输出ABC.(4) 打印输出ABC(5) 运行期抛出一个ArrayIndexOutOfBoundsException异常来。练习31:请问,以下哪些语句存在语法错误?(1) dcfault String s;(2) transient int i=41;(3) public final static native int w ();(4) abstract double d;(5) abstract final double hyperbolicCosine ();答(1
15、)(4)(5)练习32: (1)一个抽象类不能包含有final方法。 (2)一个final类不能包含有抽象方法。练习33:给出以下代码,请问哪些描述是正确的?1. final class Base2. 3. int xxx;4. void yyy ()xxx=1;5. 6.7.8.class Sub extends Base9.10.final Base finalref=new Base ();11.12.final void yyy ()13.14.System.out.println (“In method yyy ()”);15.final ref.xxx=12345;16.17.(1
16、) 从第1行去掉关键字final。(2) 从第10行去掉关键字final。(3) 去掉第15行语句。(4) 从第1行和第10行去掉关键字final。练习34: (1) transient方法不能被重载。(2) transient方法必须被重载。(3) transient类不能被序列化。(4) transient变量必须是静态变量。(5) transient变量不能被序列化。练习35:(1) 第5行和第12行代码编译错误。(2) 第12行代码编译错误。(3) 打印输出x=10(4) 打印输出x=15(5) 打印输出x=3练习36:1.class Check2.3.private static i
17、nt x=100;4.5. public static void main (String args)6.7.Check hs1=new Check();8.hs1.x+;9.Check hs2=new Check();10. hs2.x+;11. hs1=new Check();12. hs1.x+;13.Check.x+;14.System.out.println(“x=”+x);15. (1) 第8行代码编译错误。 (2) 第13行代码编译错误。 (3) 打印输出x=102 (4) 打印输出x=103 (5) 打印输出x=104练习37:给出以下代码,请问以下哪个修饰符可放置在第3行的方
18、法前?1.class Bace3.void aMethod();4.5.6.class Sub extends Base7.8.void aMethod(); (1) public(2) protected (3) private练习38:请问,以下哪些关键字修饰变量可使该变量不能被序列化?(1) private (2) protected(3) private protected(4) transient(5) private transient 该出以下代码,请回答练习09和10的问题?package abcde;public class Birdprotected static int
19、referenceCount=0;public Bird () referenceCount+;protected void fly ()static int getRefCount ()return referenceCount;给出以下代码,请问以下哪些描述是正确的?1. package abcde;2. 3.class parrot extends abcde.Bird4.public void fly ()5./ *子类Parrot的特定实现*/6.7.public int getRefCount()8.return referenceCount;10.(1) 第4行代码编译错误,因为
20、fly ()方法在其父类Bird中是protected方法。(2) 第4行代码编译错误, 因为fly ()方法在其父类Bird中是protected方法,而在子类Parrot中是public方法。(3) 第7行代码编译错误,因为getRefCount()方法在其父类Bird中是static方法, 而在子类Parrot中是非static方法。(4) 代码编译成功,但如果调用子类Parrot实例上的fly ()方法,会在运行期抛出异常来。(5) 代码编译成功,但如果调用子类Parrot实例上的getRefCount()方法,会在运行期抛出异常来。练习40:1.package singers;2.3
21、.class Nightingale extends abcde Bird4. Nightingale ()referenceCount+;6.public static void main (String args)7.System.out.print (“Before:”+referenceCount);8. Nightingale Florence=new Nightingale ();9. System.out.println(“After:10.florence.fly ()11.12.(1) 代码编译成功,打印输出0 Afer:2(2) 代码编译成功,打印输出0 Afer:1(3)
22、 第4行代码编译错误,因为静态成员不能被重载。(4) 第10行代码编译错误,因为fly ()方法在其父类Bird中是protected方法。(5) 代码编译成功,但在第10行运行期会抛出异常,因为fly ()方法在其父类Bird中是 protected方法。练习51:(1) Boolean b = new Boolean(“abcd”);(2) float f = 123;(3) byte b = 127;(4) short s = 128;练习52:请问,一个布尔型数据是否可以转换为其他数据类型?(1) 是(2) 否练习53:请问,当将一个取值范围窄的数据赋值给一个取值范围宽的变量时,Java系统是否会自动将取值范围窄的数据转换为取值范围宽的数据格式?练习54:请问,以下哪些语句不是合法的赋值语句?(1) boolean b = tru
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1