JAVA基础 第3章练习_类与对象_2012
- 格式:doc
- 大小:62.50 KB
- 文档页数:6
第3章 类与对象 一.选择题
1.下列不属于面向对象编程的特性是()。 A.封装性 B. 继承性 C. 多态性 D. 编译执行性
2.下列类的声明中不合法的是()。 A. class People{…} B. class 植物{…} C. Class A{…} D. public class 共有类{…}
3.下列方法的声明中不合法的是()。 A. float area(){…} B. void area(){…} C. double area(d){…} D. int area(int r){…}
4. 下列构造方法的调用中正确的是()。 A. 按照一般的方法调用 B. 由用户直接调用 C. 只能通过new自动调用 D. 被系统调用
5.下列程序运行的结果是()。 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.下列程序运行的结果是()。 public class A{ static void f(int y){ y=y+10; } 2
public static void main(String args[]){ double x=10; f(x); System.out.println(x); } } A. 10 B. 20 C. 10.0 D.程序编译错误
7.下列程序运行的结果是()。 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. 以下代码的输出结果为()。 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. 编译和运行程序会出现什么样的结果()。 public class Ref{ public static void main(String args[]){ Ref r = new Ref(); r.amethod(r); } 第3章练习 类与对象 大外软件学院 第3页 共6页 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. 关于以下程序代码的说明正确的是()。 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); } } 4
其输出结果是什么()。 A. The value is 8 B. The value is 9 C. The value is 10 D. The value is 11
12. 以下代码的调试结果为()。 1: public class Q21 2: { 3: int maxElements; 4: 5: void Q21() 6: { 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) {…} } 如果要创建一个该类的对象,正确的语句是()。 A. test obj1=new test(); B. test obj1=new test(5); C. test obj1=new test("5 "); D. test obj1=new test(3.4);
14. 指出下列哪个方法不能与方法public void add(int a){…}重载()。 A. public int add(int b) B. public void add(double b) C. public void add(int a, int b) 第3章练习 类与对象 大外软件学院 第5页 共6页 D. public void add(float g) 15.下面程序的输出结果是什么()。 class J_Test{ int m_i = 2; String m_s = null; J_Test(){ m_i = 3; m_s = "constructor"; } public static void main(String args[]){ J_Test app = new J_Test(); System.out.println(app.m_i+app.m_s); } } A. 2null B. 3null C. 3constructor D. 以上都不对
16. 下面程序的输出结果是什么()。 class J_Test{ int m_i = 2; String m_s = null; void J_Test(){ m_i = 3; m_s = "constructor"; } public static void main(String args[]){ J_Test app = new J_Test(); System.out.println(app.m_i+app.m_s); } } A. 2null B. 3null C. 3constructor D. 以上都不对
17.下列代码的运行结果是()。 public class J_Test{ static short m_index; static int m_age; public static void mb_setData(long n){ m_index = n; } public static void main(String args[]){ mb_setData(98); System.out.println("Index=" + m_index + ";Age="+m_age); } }