报名本机构合作学校,赠送复习资料,复习课程,确保录取。并且可以申请学校奖学金500元~1500元不等!
第2章编程作业
第2章的单元测验
1、【单选题】一个 int 类型的整数和一个 double 类型的数进行加法运算,则结果类型为
A、int
B、double
C、float
D、long
2、【单选题】设 a = 8,则表达式 a 2 的值是
A、16
B、2
C、8
D、4
3、【单选题】用八进制表达 8 的值,正确的是?
A、0x10
B、010
C、08
D、0x8
4、【单选题】要产生[20,999]之间的随机整数使用( )表达式。
A、(int)(20+Math.random()*979)
B、20+(int)(Math.random()*980)
C、(int)Math.random()*999
D、20+(int)Math.random()*980
5、【单选题】表达式 1+2+ x+3 的值是
A、"12x3"
B、"3x3"
C、"6x"
D、"x6"
6、【单选题】整型变量a,b的值定义如下: int a = 21; int b = 22;则表达式 ++a == b++ 的值为:
A、false
B、21
C、true
D、22
7、【单选题】下列叙述中,正确的是?
A、声明变量时必须指定一个类型
B、java认为变量number与Number相同
C、Java中唯一的注释方式是"//"
D、一个源文件中public类可以有0或多个
8、【单选题】以下数据类型转换中,必须进行强制类型转换的是
A、int→char
B、short→long
C、float→double
D、int→double
9、【单选题】以下程序的运行结果为class test { public static void main(String args[]) { int x=2; System.out.printf(%d,%d,%d, x++ , x, ++x); }}
A、3,3,3
B、2,3,4
C、2,2,3
D、3,3,4
10、【单选题】以下哪个方法的调用结果是整数类型结果3
A、Math.ceil(3.1)
B、Math.floor(2.7)
C、Math.abs(3.1)
D、Math.round(2.7)
11、【单选题】利用Scanner对象从输入数据源获取一个整数的方法是?
A、next()
B、nextInt()
C、nextLine()
D、nextDouble()
12、【多选题】下列选项中( )是合法的 Java 标识符名字。
A、$index
B、name-7
C、_byte
D、char
13、【多选题】下面各项中定义变量及赋值正确的有( )。
A、int i = 32;
B、float f = 45.0;
C、double d = 45.0;
D、long x = (long)45.0;
14、【多选题】设有类型定义 int x=24;long y=25;下列赋值语句正确的是
A、y=x;
B、x=y;
C、x=(int)y;
D、y=x+2;
15、【多选题】以下变量定义和初始化中哪些编译正确?
A、short myshort = 99S;
B、String name = 'Excellent tutorial Mr Green';
C、char c = 17;
D、int z = 015;
16、【填空题】思考程序段对应的运行结果int a = 2;int y = a++;++a;System.out.printf( %d,%d, a, y);
A、
17、【填空题】写出程序段对应的运行结果int x = 4;System.out.print( "x=" +((x 4) ? 99.99 : 9));
A、
18、【填空题】写出程序段对应的输出结果int x = 125;System.out.print(x/10);
A、
19、【填空题】写出程序段对应的运行结果int x = 125;System.out.print(x%3==0);
A、
20、【填空题】在Java中int类型变量占用空间是4个字节,char类型变量分配空间是 ( )个字节
A、
流程控制语句作业
第3章单元测验
1、【单选题】以下程序的运行结果为( )。public class Test { public static void main(String args[ ]) { int i=0, j=2; do { ++i; j--; } while(j0); System.out.println(i); }}
A、0
B、1
C、2
D、3
2、【单选题】执行以下程序后,输出结果为( )。public class Ex2{ public static void main(String args[ ]) { int k ,f=1; for (k=2;k5;k++) f = f * k; System.out.println(k); }}
A、1
B、4
C、5
D、24
3、【单选题】设有如下类:class Loop{ public static void main(String[ ] args) { int x=0;int y=0; outer: for(x=0;x100;x++){ middle: for(y=0;y100;y++){ System.out.println(x=+x+; y=+y); if (y==10) { insert code } } } }}在insert code处插入什么代码可以结束外循环?
A、continue middle;
B、break outer;
C、break middle;
D、continue outer;
4、【单选题】以下循环的执行次数是( )。int x=4,y=2;while (--x!=x/y) { }
A、1
B、2
C、3
D、4
5、【单选题】以下程序段的输出结果为( )。int x=1;for (x=2;x=10;x++ ) ;System.out.print(x);
A、1
B、2
C、10
D、11
6、【单选题】设 int x=2,y=3,则表达式(y-x==1)?(!true?1:2):(false?3:4)的值为( )。
A、1
B、2
C、3
D、4
7、【单选题】以下程序段对应的运行结果为?int j = 1;while(j5){ if(j == 1) continue; j++; System.out.print(j);}
A、1
B、234
C、无限循环
D、2345
8、【单选题】若a的值为3时,下列程序段被执行后,c的值是多少? int c = 1; if ( a0 ) if ( a3 ) c = 2; else c = 3; else c = 4;
A、2
B、3
C、1
D、4
9、【单选题】以下程序的运行结果为public class test { public static void main(String args[]) { int i = 1; do { i--; } while (i 2); System.out.print(i); }}
A、1
B、2
C、-1
D、0
10、【单选题】下面的代码段的输出结果为? int count = 0; for (int i = 1; i 4; i++) count += i; System.out.println(count);
A、4
B、1
C、6
D、10
11、【单选题】下列语句片段的结果为: int result; int a = 17, b = 6; result = (a % b 4)? a % b : a / b ; System,out.println(result);
A、0
B、1
C、2
D、5
12、【多选题】outer: for( int i =1; i3 ;i++) { inner : for ( j= 1;j3;j++) { if (j==2) continue outer: System.out.prinltn(i= + i ,j = + j) } } 该代码段的输出结果含有?
A、i= 1,j= 1
B、i= 1,j= 2
C、i= 2,j= 1
D、i= 2,j= 2
13、【多选题】设有如下代码段, x为哪些数时输出内容中含有 "Test2" ? switch (x) { case 1 :System.out.println("Test1"); case 2 : case 3 :System.out.println("Test2");break; } System.out.println("Test3");
A、0
B、1
C、2
D、3
14、【填空题】写出以下程序段对应的运行结果String c="red";switch (c) { default: System.out.print("white"); break; case "red": System.out.print("red"); break; case "blue": System.out.print("blue");}
A、
15、【填空题】写出以下程序段对应的输出结果int x = 23659;String m = "result=";while (x0) { m = m + x%10; x = x/10;}System.out.print(m);
A、
16、【填空题】写出以下程序段对应的执行结果 int i = 10,j = 10; boolean b = false; if ( b = i == j) System.out.print(True); else System.out.print(False);
A、
17、【填空题】写出程序的运行结果class Test{ public static void main(String args[]) { int x = 5634; int s = 0; while (x0) { s = s + x%10; x = x/10; } System.out.print("s="+s); }}
A、
数组应用编程作业
方法设计编程作业
类与对象的测验
1、【单选题】以下代码的编译运行结果为( )。public class Test { public static void main(String args [ ]){ int age; age = age + 1; System.out.println(The age is + age); }}
A、编译通过,运行无输出
B、编译通过,运行输出:The age is 1
C、编译通过,但运行时出错
D、不能通过编译
2、【单选题】以下代码的输出结果为( )。public class Test{ int x=5; public static void main(String argv[ ]){ Test t=new Test(); t.x++; change(t); System.out.println(t.x); } static void change(Test m){ m.x+=2; }}
A、7
B、6
C、5
D、8
3、【单选题】设有如下代码public class Test{ long a[ ] = new long[10]; public static void main( String arg[ ] ){ System.out.println(a[6]); }}叙述正确的是( )。
A、输出 null
B、输出 0
C、出现编译错误
D、运行出错
4、【单选题】给出如下不完整类:class Person { String name, department; int age; public Person(String n){ name = n; } public Person(String n, int a){ name = n; age = a; } public Person(String n, String d, int a){ //给属性 name,age 赋值,比如:name=n;age=a; department = d; } } 可取代注释部分位置内容达到注释的目标的是( )。
A、Person(n,a);
B、this(Person(n,a));
C、this(n,a);
D、this(name,age);
5、【单选题】设有以下程序,其运行输出结果为?class Test{ Test(int i) { System.out.println(Test( +i +)); }}public class Q12 { static Test t1 = new Test(1); Test t2 = new Test(2); static Test t3 = new Test(3); public static void main(String[ ] args){ Q12 Q = new Q12(); }}
A、Test(1)Test(2)Test(3)
B、Test(3)Test(2)Test(1)
C、Test(2)Test(1)Test(3)
D、Test(1)Test(3)Test(2)
6、【单选题】运行下列代码后,正确的结果为: public class Test { static int age; public static void main (String args []) { age = age + 1; System.out.println("age=" + age); }}
A、编译运行后无任何输出
B、编译运行后输出 age=1
C、编译运行后输出 age=0
D、编译出错
7、【单选题】以下程序的运行结果为?public class Test { static int count; public static void main(String args[]) { int sum=0; for (int count=0;count4;count++) sum+=count; System.out.println(count); }}
A、4
B、3
C、6
D、0
8、【单选题】考虑如下类: public class Test { public static void test() { this.print(); } public static void print() { System.out.println(Test); } public static void main(String args []) { test(); }} 则程序调试结果为?
A、输出Test
B、无输出结果.
C、编译错误,不能在静态上下文环境中引用 this
D、无构造方法,不能创建对象
9、【单选题】给出下面代码: public class Person{ static String arr[] = new String[5]; public static void main(String args[ ]) { System.out.println(arr[1]); } } 以下那个说法正确?
A、编译时将产生错误
B、编译正确,运行时将产生错误
C、输出0
D、输出null
10、【单选题】针对以下程序的表述正确的是?public class Test { public static void print() { System.out.println(Test); } public static void main(String args []) { this.print(); }}
A、输出Test
B、抛出对象未创建的运行异常
C、在标准输出设备上无输出结果.
D、编译错误,不能在静态上下文环境中引用 this
11、【单选题】针对以下程序的描述哪个正确?public class User{ String name; public static void main(String args []) { User u=new User(); System.out.println(u.name); }}
A、输出结果为null
B、出现编译错误,因为没有定义构造方法,
C、编译错误,因为name没有赋值,不能访问
D、运行出现异常
12、【单选题】以下程序的调试输出结果是?public class Test {{System.out.println(init);} static { System.out.println(static); } public void print() { System.out.println(Hello); } public static void main(String args []) { new Test().print(); }}
A、initstaticHello
B、Hello
C、staticinitHello
D、程序编译错误
13、【单选题】编译和运行程序会出现什么结果?public class Ref{ int i=100; public static void main(String argv[]){ Ref r = new Ref(); r.i++; r.amethod(new Ref()); } public void amethod(Ref r){ System.out.println(i); System.out.println(r.i); }}
A、出现编译出错
B、100101
C、101100
D、101101
14、【单选题】编译和运行程序会出现什么结果?public class Ref{ static int i=100; public static void main(String argv[]){ Ref r = new Ref(); i++; r.amethod(new Ref()); } public void amethod(Ref r){ System.out.println(i); System.out.println(r.i); }}
A、出现编译错误
B、101101
C、100101
D、101100
15、【单选题】以下程序的执行结果为?public class Test { int count=8; public void m( ){ for(int count=1;count2;count++) System.out.print(count); System.out.print(count); } public static void main(String args[ ]) { new Test().m( ); }}
A、12
B、123
C、128
D、18
16、【多选题】考虑如下类: public class Test { int j,k; public Test(int j ) { this(j,0); } public Test(int j, int k) { this.j=j; this.k=k; } } 以下哪些可正确创建Test对象?
A、Test t = new Test();
B、Test t = new Test(1);
C、Test t = new Test(1, 2);
D、Test t = new Test("1");
17、【多选题】思考如下代码: import iava.util.Date; // 一X— public class Quiz4_8{ // class definition }下列哪些是合法的语句可以插入到-X-标记的行中?
A、import java.util.Arrays;
B、package chapter5;
C、class AnotherClass{ }
D、public class AthirdClass{ }
18、【填空题】写出程序的运行结果class Test { static int x=5; static { x+=10; } public static void main(String args[ ]){ System.out.println("x="+x); } static { x=x-5; }}
A、
19、【填空题】写出程序的运行结果public class Ex1{ static int m=2; public static void main(String args[ ]) { Ex1 obj1 = new Ex1(); Ex1 obj2 = new Ex1(); obj1.m = m + 1; System.out.println(m=+obj2.m); }}
A、
20、【填空题】写出程序运行结果public class My{ int value; public static void main(String args[]) { My x = new My(); if (x==null) System.out.print("No Object"); else System.out.print(x.value); } }
A、
21、【填空题】以下程序执行结果为?public class My{ int value; public static void main(String args[]) { My x = new My(); My y = x; x.value+=1; System.out.println(y.value); } }
A、
22、【填空题】以下程序的运行结果为?public class A { int v; { v++; } public A( ) { v=v+2; } public static void main(String args[ ]) { A m = new A(); System.out.println(v=+m.v); }}
A、
继承与多态的测验
1、【单选题】以下程序调试结果为( )。public class Test { int m = 5; public void some(int x) { m = x; } public static void main(String args[ ]) { new Demo().some(7); }}class Demo extends Test { int m = 8; public void some(int x) { super.some(x); System.out.println(m); }}
A、5
B、8
C、7
D、无任何输出
2、【单选题】类Test1定义如下:1.public class Test1{2. public float aMethod(float a,float b){ }3. 4.} 下面方法中插入行3处为不合法的是( )。
A、public float aMethod(float a, float b,float c){ }
B、public float aMethod(float c,float d){ }
C、public int aMethod(int a, int b){ }
D、private float aMethod(int a,int b,int c){ }
3、【单选题】为了使下面的程序能通过编译,最少要做的修改是( )。1. final class A {2. int x;3. void mA() { x=x+1; }4. }5. class B extends A {6. final A a=new A();7. final void mB(){8. a.x=20; 9. System.out.println(hello);10. }11. }
A、第1行去掉final
B、第6行去掉final
C、删除第8行
D、行1和行6去掉final
4、【单选题】以下程序调试结果为:private class Base{ Base(){ int i = 100; System.out.println(i); } } public class Pri extends Base{ static int i = 200; public static void main(String argv[]){ Pri p = new Pri(); System.out.println(i); } }
A、编译错误
B、200
C、100
D、200100
5、【单选题】class Person {
private int a;
public int change(int m){ return m; }
}
public class Teacher extends Person {
public int b;
public static void main(String arg[]){
Person p = new Person();
Teacher t = new Teacher();
int i;
// point x
}
}
在 // point x安排哪个语句合法?
A、i = m;
B、i = b;
C、i = p.a;
D、i = p.change(30);
6、【单选题】int型public成员变量MAX_LENGTH,该值保持为常数100,则定义这个变量的语句是
A、public int MAX_LENGTH=100;
B、final int MAX_LENGTH=100;
C、public final int MAX_LENGTH=100;
D、public const int MAX_LENGTH=100;
7、【单选题】设有如下类定义:1. class BaseWidget extends Object{2. String name=BaseWidget;3. void speak(){System.out.println(I am a +name);}4. }5. class TypeAWidget extends BaseWidget{6. TypeAWidget(){name=TypeA;}7. } 以下哪段代码将正确编译和执行A). Object A = new BaseWidget(); A.speak();B). BaseWidget B = new TypeAWidget(); B.speak();C). TypeAWidget C = new BaseWidget(); C.speak();D). Object C = new TypeAWidget(); C.speak();
A、Object A = new BaseWidget(); A.speak();
B、BaseWidget B = new TypeAWidget(); B.speak();
C、TypeAWidget C = new BaseWidget(); C.speak();
D、 Object C = new TypeAWidget(); C.speak();
8、【单选题】在构造方法的哪个地方可以调用父类的构造方法?
A、任何地方
B、构造方法中的第一条语句
C、构造方法中的最后一条语句
D、不能在构造方法中调用super()
9、【单选题】定义常量时使用的关键字是?
A、static
B、const
C、final
D、public
10、【单选题】哪个关键词用来代表当前对象的引用?
A、static
B、super
C、this
D、class
11、【单选题】以下关于java子类和父类关系,哪个正确?
A、一个子类可以有多个直接父类,一个父类也可以有多个子类
B、一个子类可以有多个直接父类,但一个父类只可以有一个子类
C、一个子类只能有一个直接父类,但一个父类可以有多个子类
D、上述说法都不对
12、【单选题】哪种访问组合可放在第3行aMethod()前和第8行的aMethod()前? 1. class SuperDuper 2. { 3. void aMethod() { } 4. } 5. 6. class Sub extends SuperDuper 7. { 8. void aMethod() { } 9. }
A、line 3: public; line 8: private
B、line 3: protected; line 8: private
C、line 3: private; line 8: protected
D、line 3: public; line 8: protected
13、【单选题】考虑如下类: 1. class Cruncher ( 2. void crunch(int i) { 3. System.out.println(int version); 4. } 5. void crunch(String s) { 6. System.out.println(String version); 7. } 8. 9. public static void main(String args[]) { 10. Cruncher crun = new Cruncher( ); 11. char ch = 'p'; 12. crun.crunch(ch); 13. } 14. }以下哪个为真?
A、第12行编译出错,因为crunch()以字符作为参数
B、代码编译通过,但运行时在12行将抛出异常
C、代码输出: int version
D、代码输出: String version
14、【多选题】考虑如下类:public class Sub extends Base { public Sub(int k) { } public Sub(int m,int n) { super(m,n); …}}假设Base类与Sub类在同一包中,则在Base类中必须存在的构造方法是( )。
A、Base()
B、Base(int k) { }
C、Base(int m,int k) { }
D、Base(int i,int j,int k) { }
15、【多选题】给出下面的类:public class Sample{ long length; public Sample(long x){ length = x; } public static void main(String arg[ ]){ Sample s1, s2, s3; s1 = new Sample(21L); s2 = new Sample(21L); s3 = s2; long m = 21L; } } 下面表达式中返回false的是( )。
A、s1 == s2
B、s2 == s3
C、new Sample(m) == s1
D、s1.equals(m)
16、【多选题】设有如下代码:public class Parent { int change() {…} } class Child extends Parent { } 下面方法中可被加入类Child中是( )。
A、public int change(){ ... }
B、int chang(int i){ ... }
C、private int change(){ ... }
D、abstract int chang(){ ...}
17、【多选题】已知方法 public void example() {...}下列选项中能正确重载该方法的是?
A、public void example( int m) {...}
B、public void example() {...}
C、public void example2() {...}
D、public int example( int m, float f) {...}
18、【多选题】设有如下代码:class Base{}public class MyCast extends Base{ static boolean b1=false; static int i = -1; static double d = 10.1; public static void main(String argv[]){ MyCast m = new MyCast(); Base b = new Base(); //Here }}则在 //Here处插入哪个代码将不出现编译和运行错误?
A、b=m;
B、m=b;
C、d =i;
D、b1 =i;
19、【填空题】以下程序的输出结果为?public class Parent { public Parent(){ System.out.print(parent()); } public void m(int x){ System.out.print(x); }}class Child extends Parent { public Child() { System.out.print(child()); } public static void main(String arg[]){ new Child().m(5); }}
A、
20、【填空题】以下程序的输出结果为?public class Parent { int x=5; { x++; }}class Child extends Parent { int x=8; public static void main(String args[]){ Parent x=new Child(); System.out.println(x.x); }}
A、
21、【填空题】以下程序的输出结果为?public class Parent { int x=5; { x++; }}class Child extends Parent { public Child() { x=x+2; } public static void main(String args[]){ Child a=new Child(); System.out.println(a.x); }}
A、
22、【填空题】以下程序的运行结果为public class A { void test(Object obj) { System.out.print(Object: + obj ); } void test(double m) { System.out.print(double: + m); } public static void main (String[ ] args) { A a1 = new A(); a1.test(5); a1.test(5); }}
A、
常用类型类使用作业
常用数据类型处理测验
1、【单选题】写出以下程序的运行结果?public class Test{ public static void main(String argv[]){ String s = new String(hello); myMethod(s); System.out.print(s= + s); } public static void myMethod(String s){ s = s + !; }}
A、s=hello!
B、s=hello
C、hello!
D、hello
2、【单选题】设有字符串s赋值如下:String s = "hi,你好";则s.length()的值为?
A、4
B、5
C、3
D、7
3、【单选题】以下哪个表达式被编译认为不合法?
A、String x="Hello"; int y=9; x+=y;
B、String x="Hello"; int y=9; if (x==y) { }
C、String x="Hello"; int y=9; x=x+y;
D、String x=null; int y=x.length();
4、【单选题】有如下程序段:public class ish{ public static void main(String[] args) { String s=call me!; System.out.print(s.charAt(s.length()-1)); }}
A、e
B、c
C、!
D、s
5、【单选题】设有下面两个赋值语句:a = Integer.parseInt(1024);b = Integer.valueOf(1024).intValue();不考虑赋值中的自动包装转换,你认为a,b最适合的数据类型是?
A、a是int类型变量,b是Integer类对象。
B、a是Integer类对象,b是int类型变量。
C、a和b都是Integer类对象并且它们的值相等。
D、a和b都是int类型变量并且它们的值相等。
6、【单选题】以下程序的运行结果为?class test{ public static void main(String args[]) { String s = Java是面向对象的语言,JavaScript是脚本语言; int k = -1; k = s.indexOf( '是', k + 1); System.out.print(k); }}
A、-1
B、4
C、23
D、5
7、【单选题】关于以下程序段,正确的说法是( )1. String s1=abc+def;2. String s2=new String(s1);3. if(s1==s2)4. System.out.println(= = succeeded);5. if (s1.equals(s2))6. System.out.println(.equals() succeeded);
A、行4与行6都将执行
B、行4执行,行6不执行
C、行6执行,行4不执行
D、行4、行6都不执行
8、【单选题】如下代码: public class Quiz3_2{ public static void main(String[] args){ String a=Hello; String b=World!; f( a, b ); System.out.println(a); } public static void f(String x, String y) { x += y; } } 下述哪条叙述正确描述了程序编译和运行的行为?
A、编译成功,输出为“Hello”
B、编译成功,输出为“World!”
C、编译成功,输出为“Hello World!”
D、编译拒绝表达式x+=y, 因为不能改变一个String对象的值
9、【单选题】如下代码: public class Ref{ public static void main(String[] args) { StringBuffer sbl = new StringBuffer(Hello); StringBuffer sb2 = new StringBuffer(Hello); boolean result = sbl.equals(sb2); System.out.println(result); } } 下述哪条陈述正确描述了程序行为?
A、输出为 true
B、输出为 false
C、输出为 0
D、输出为 1
10、【单选题】调用以下类D和E的main() 方法的输出结果为?class D { public static void main(String[] args) { String s1 = new String(hello); String s2 = new String(hello); if (s1.equals(s2)) System.out.println(equal); else System.out.println(not equal); }} class E { public static void main(String[] args) { StringBuffer sb1 = new StringBuffer(hello); StringBuffer sb2 = new StringBuffer(hello); if (sb1.equals(sb2)) System.out.println(equal); else System.out.println(not equal); }}
A、D: equal; E: equal
B、D: not equal; E: not equal
C、D: equal; E: not equal
D、D: not equal; E: equal
11、【单选题】以下哪个方法用来从字符串中获取一个字符?
A、indexOf(String str)
B、split(String str,char ch)
C、concat(String str)
D、charAt(int index)
12、【多选题】设有一个字符串s赋值如下: String s="hello";要获得字符串中的首个字符构成的子串可以用哪些方法?
A、s.startsWith()
B、s.substring(0,1)
C、""+s.charAt(0)
D、String.valueOf(s.charAt(0))
13、【多选题】要将整数25转换为二进制形式的数字串,可以用哪些方法?
A、Integer.toBinaryString(25)
B、Integer.toString(25,2)
C、Integer.toString(25)
D、Integer.parseInt("25",2)
14、【多选题】给出如下定义:String s = " Example "; 选出合法代码
A、s[3] = "x";
B、 int i = s.length();
C、String t = "For " + s;
D、String shortS = s.trim();
15、【多选题】设有如下代码 class StringTest { public static void main (String [] args){ String a="Hello"; StringBuffer c=new StringBuffer ("Hello"); String b="Hello"; StringBuffer d =new StringBuffer ("Hello"); if (<>>) {} }} 在<>>位置替换为以下哪个条件为真?
A、b.equals(a)
B、b==a
C、c==d
D、d.equals( c)
16、【多选题】假设ch为字符类型变量,要判断ch是否为数字字符,用那种方法?
A、ch>='0' && ch<='9'
B、ch-'0'>=0
C、Character.isDigit(ch)
D、0< =ch<=9
17、【填空题】以下程序的运行结果为?public class Test5{ public static void main(String argv[]){ StringBuffer x = new StringBuffer(你好); myMethod(x); System.out.print(x= + x); } public static void myMethod(StringBuffer s){ s.append(,Hi); }}
A、
18、【填空题】写出以下程序运行结果public class test { public static void main(String a[]){ int x=12653; String m=+x; StringBuffer b=new StringBuffer(); for (int k=0; k m.length(); k++) { b.insert(0,m.charAt(k)); } System.out.print(b); }}
A、
19、【填空题】以下程序运行结果为?public class test { public static void main(String args[]) { String s1 = "abc"; String s2 = new String("abc"); if(s1 == s2) System.out.print(1); else System.out.print(2); if(s1.equals(s2)) System.out.print(3); else System.out.print(4); }}
A、
20、【填空题】以下代码的输出结果?public class Test{ public static void main(String argv[]){ String x=hello; change(x); System.out.println(x); } static void change(String m){ m=m+2; }}
A、
21、【填空题】设有一个字符串s的内容为welcome to China!,则, s.substring(3,8)的结果为?
A、
抽象类与接口测验
1、【单选题】以下程序的调试结果为( )。public class Outer{ public String name = Outer; public static void main(String argv[]){ Inner i = new Inner(); i.showName(); } private class Inner{ String name = new String(Inner); void showName(){ System.out.println(name); } }}
A、输出结果 Outer
B、输出结果 Inner
C、编译错误,因 Inner 类定义为私有访问
D、在创建 Inner 类实例的行出现编译错误
2、【单选题】有关内嵌类以下哪个叙述为假?
A、内嵌类可以访问外部类的成员
B、方法中的内嵌类可以访问方法中定义的常量
C、匿名内嵌类没有对应的字节码文件
D、内嵌类可以被定义为静态成员
3、【单选题】以下程序的编译和运行结果为?abstract class Base{ abstract public void myfunc(); public void another(){ System.out.println(Another method); }}public class Abs extends Base{ public static void main(String argv[]){ Abs a = new Abs(); a.amethod(); } public void myfunc(){ System.out.println(My Func); } public void amethod(){ myfunc(); }}
A、输出结果为 My Func
B、编译指示 Base 类中存在抽象方法
C、编译通过,但运行时指示Base 类中存在抽象方法
D、编译指示Base 类中的myfunc方法无方法体,没谁会喜欢该方法。
4、【单选题】以下代码的调试结果为?abstract class MineBase { abstract void amethod(); static int i;}public class Mine extends MineBase{ public static void main(String argv[]){ int[] ar = new int[5]; for(i = 0;i ar.length;i++) System.out.println(ar[i]); }}
A、输出5个0
B、编译错误指示"ar 未初始化就使用"
C、编译错误指示"Mine 必须定义为抽象类"
D、运行错误, i超出数组下标范围
5、【单选题】若在某一个类定义中定义有如下的方法:
abstract void performDial( );
该方法属于?
A、本地方法
B、最终方法
C、多态方法
D、抽象方法
6、【单选题】以下哪个正确定义抽象类?
A、class Animal { abstract void growl(); }
B、abstract Animal {abstract void growl();}
C、class abstract Animal {abstract void growl();}
D、abstract class Animal {abstract void growl();}
7、【单选题】如下源文件中的代码: interface Calculator{ public void calculate(); } interface Microwave{ public void cook(); } public class Quiz5_2 implements Calculator,Microwave{ public void calculate() { System.out.println(calculating); } public void cook() { System.out.println(cooking); } public static void main(String[] args) { Quiz5_2 x=new Quiz5_2(); x.calculate(); x.cook(); } } 当代码被编译和运行时下列哪条语句是正确的?
A、编译器立即拒绝实现两个接口的企图
B、编译器拒绝类Quiz5_2的定义,因为它实现了两个接口,却没有继承任何类
C、编译成功,输出如下:calculatingcooking
D、编泽器显示了一个错误,因为接口和类不是在分离的源文件中
8、【多选题】设有类定义如下:class InOut{ String s = new String(Between); public void amethod(final int iArgs){ int iam = 5; iam++; class Bicycle{ public void sayHello(){ //Here } } } public void another(){ int iOther; }}以下可以安排在//Here 处的语句有( )。
A、System.out.println(s);
B、System.out.println(iOther);
C、System.out.println(iam);
D、System.out.println(iArgs);
9、【多选题】有关抽象类,以下说法正确的是( )。
A、不能派生子类;
B、不能对该类实例化;
C、所有方法均为抽象方法;
D、类定义包含 abstract 关键字。
10、【多选题】设有如下代码:interface IFace{}class CFace implements IFace{}class Base{}public class ObRef extends Base{ public static void main(String argv[]){ ObRef obj = new ObRef(); Base b = new Base(); Object obj1 = new Object(); IFace obj2 = new CFace(); //Here }}则在//Here 处插入( )代码将不出现编译和运行错误。
A、obj1=obj2;
B、b=obj;
C、obj=b;
D、obj1=b;
11、【多选题】以下叙述哪个为真?
A、如果有import语句,必须是程序中第一个非注释语句.
B、私有成员可被同一包中的所有类访问
C、抽象类不能被定义为final
D、局部变量不能添加 static修饰
12、【多选题】下列说法正确的是?
A、java中的子类只允许有一个父类
B、子类继承了父类的所有方法(包括构造方法)
C、一个类可以根据需要实现多个接口
D、一个类定义时没指定父类,则继承Object类
13、【填空题】写出程序运行结果abstract class P{ public P() { System.out.print("parent"); } abstract void m();}class S extends P { public S() { System.out.print("child"); } public static void main(String a[ ]) { P x= new S(); x.m(); } void m() {System.out.print("m()"); }}
A、
14、【填空题】用_____修饰符修饰的方法是抽象方法。
A、
15、【填空题】用___________修饰符修饰的类不能派生子类
A、
16、【填空题】用___________修饰符修饰的成员只能在本类中直接访问.
A、
17、【填空题】以下程序的运行结果为?abstract class Parent{ int x=20; abstract void dosomething();}class Sub extends Parent { int x=30; public static void main(String a[ ]) { Parent x= new Sub(); x.dosomething(); } void dosomething() {System.out.print("努力"+x); }}
A、
微信扫码添加好友
如二维码无法识别,可拨打 13662661040 咨询。