JAVA基础 第3章类与对象_练习题_200910

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

第3章类与对象

一.选择题

1.下列不属于面向对象编程的特性是(D)。

A.封装性 B. 继承性 C. 多态性 D. 编译执行

2.下列类的声明中不合法的是(C)。

A. class People{…}

B. class 植物{…}

C. Class A{…}

D. public class 共有类{…

3.下列方法的声明中不合法的是(C)。

A. float area(){…}

B. void area(){…}

C. double area(d){…}

D. int area(int r){…}

4. 下列构造方法(构造器)的调用中正确的是(C)。

A. 按照一般的方法调用

B. 由用户直接调用

C. 只能通过new自动调用

D. 被系统调用

5.下列程序运行的结果是(A)。

class Book{

int width;

int length;

}

public class A{

static void f(Book p){

p.width=20;

p.length=40;

}

public static void main(String args[]){

Book b=new Book();

b.width=10;

b.length=20;

f(b);

System.out.print(" "+b.width);

System.out.print(" "+b.length);

}

}

A. 20 40

B. 10 40

C. 10 20

D. 以上都不对

6.下列程序运行的结果是(D)。

public class A{

static void f(int y){

y=y+10;

}

public static void main(String args[]){

double x=10;

f(x);

System.out.println(x);

}

}

A. 10

B. 20

C. 10.0

D. 程序编译错误

7.下列程序运行的结果是(C)。

public class A{

int z=20;

static void f(int y){

y=z;

System.out.println(y);

}

public static void main(String args[]){

f(10);

}

}

A. 10

B. 20

C. 程序编译错误

D. 以上都不对

8. 以下代码的输出结果为(C)。

public class Pass{

static int j=20;

public static void main(String args[]){

int i=10;

Pass p = new Pass();

p.amethod(i);

System.out.println(i+" and "+j);

}

public void amethod(int x){

x=x*2;

j=j*2;

}

}

A.错误: 方法参数与变量不匹配

B. 20 and 40

C. 10 and 40

D. 10 and 20

9. 编译和运行程序会出现什么样的结果(A)。

public class Ref{

public static void main(String args[]){

Ref r = new Ref();

r.amethod(r);

}

public void amethod(Ref r){

int i=99;

multi(r);

System.out.println(i);

}

public void multi(Ref r){

r.i = r.i * 2;

}

}

A.编译出错 B. 输出:99 C. 输出:198 D. 运行出错10. 关于以下程序代码的说明正确的是(D)。

1.class HasStatic{

2. static int x=100; int y=0;

3. public static void main(String args[]){

4. HasStatic hs1=new HasStatic();

5. hs1.x++;

6. HasStatic hs2=new HasStatic();

7. hs2.x++;

8. hs1=new HasStatic();

9. hs1.x++;

10. HasStatic.x- -;

11. System.out.println("x="+x);

12. }

13.}

A.5行不能通过编译,因为引用了私有静态变量

B.10行不能通过编译,因为x是私有静态变量

C.程序通过编译,输出结果为:x=103

D.程序通过编译,输出结果为:x=102

11. 有如下代码:

public class Test {

void printValue(int m){

do {

System.out.println("The value is"+m);

}while( --m > 10 );

}

public static void main(String arg[]) {

int i=10;

Test t= new Test();

t.printValue(i);

}

}

其输出结果是什么(C)。

A. The value is 8

B. The value is 9

C. The value is 10

D. The value is 11

12. 以下代码的调试结果为(D)。

1. public class Q21

2. {

3. int maxElements;

4.

5. void Q21()

6. {

相关文档
最新文档