发布时间 : 星期六 文章JAVA基础 第3章类与对象 - 练习题 - 200910更新完毕开始阅读52b32479ec3a87c24128c4be
Java基础 第3章练习题 大外软件学院
第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(\ System.out.print(\ }
}
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); }
}
第1页 共13页
Java基础 第3章练习题 大外软件学院
A. 10 B. 20 C. 10.0 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. 程序编译错误 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+\ }
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;
第2页 共13页
D. 程序编译错误 D. 以上都不对 Java基础 第3章练习题 大外软件学院
}
}
A.编译出错 B. 输出:99 C. 输出:198 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(\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(\
}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. {
D. 运行出错
第3页 共13页
Java基础 第3章练习题 大外软件学院
7. maxElements = 100;
8. System.out.println(maxElements); 9. } 10.
11. Q21(int i) 12. {
13. maxElements = i;
14. System.out.println(maxElements); 15. } 16.
17. public static void main(String[] args) 18. {
19. Q21 a = new Q21(); 20. Q21 b = new Q21(999); 21. } 22. }
A. 输出 100 和 999 B.输出 999 和 100
C.第3行出现编译错误, 变量 maxElements 未初始化 D. 第19行出现编译错误 13. 给出如下类定义:
public class test { test(int k) {?}
}
如果要创建一个该类的对象,正确的语句是(B)。
A. test obj1=new test(); B. test obj1=new test(5); C. test obj1=new test(\D. test obj1=new test(3.4); 14. 指出下列哪个方法不能与方法public void add(int a){?}重载(A)。
A. public int add(int b) B. public void add(double b) C. public void add(int a, int b) D. public void add(float g) 15.下面程序的输出结果是什么(C)。
class J_Test{ int m_i = 2; String m_s = null; J_Test(){ m_i = 3; m_s = \ } public static void main(String args[]){ J_Test app = new J_Test(); System.out.println(app.m_i+app.m_s); }
第4页 共13页