发布时间 : 星期四 文章《Java面向对象编程》练习题更新完毕开始阅读
4、假设有这样的数组创建:int a[]={1,2,3,4,5,6,7};则该数组长度为 D 。 A.4 B.5
C.6
D.7
5、下列二维数组的创建中错误的是 D 。 A.int a[][]=new int[3][] ; B.int[][] a=new int[3][4] ; C.int a[][]={{1,2},{3,4}} ; D.int [][] a=new int[][];
**专题5 面向对象 一、填空题
1. 如果一个方法不返回任何值,则该方法的返回值类型为 void 。
2. 如果子类中的某个方法名、返回值类型和_传递参数_______与父类中的某个方法
完全一致,则称子类中的这个方法覆盖了父类的同名方法。 3. 接口中所有的属性均为_公有__、__静态_____和_常量_____的
4. 抽象 方法是一种仅有方法声明,没有具体方法体和操作实现的方法,该方
法必须在 抽象类 类之中定义。(抽象类,接口)
5. 在Java程序中,通过类的定义只能实现 单 重继承,但通过 接口 的定
义可以实现多重继承关系。
6. 一般Java程序的类主体由两部分组成:一部分是 成员变量 (属性) ,另一
部分是 成员函数 (方法) 。
7. 分别用 class 关键字来定义类,用 new 关键字来分配实例存储空间。 8. 当一个类的修饰符为 private 时,说明该类不能被继承,即不能有子类。 9. 在Java中,能实现多重继承效果的方式是 implements 。
二、选择题
1. 方法内定义的变量( )。
A.一定在方法内所有位置可见 B.可能在方法的局部位置可见 C.在方法外可以使用 D.在方法外可见
2. 方法的形参()。
9
A.可以没有
B.至少有一个 C.必须定义多个形参
D.只能是简单变量 3. return语句(D)
A.不能用来返回对象 B.只可以返回数值 C.方法都必须含有
D.一个方法中可以有多个 4. main()方法的返回值类型是(C。
A.boolean B.int C.void
D.static
5. 编译并运行下面的程序,运行结果是( )。
public class A{
public static void main(String args[]){ A a=new A(); a.method(8); }
void method(int i){
System.out.println(“int: ”+i); }
void method(long i){
System.out.println(“long: ”+i); }
A.程序可以编译运行,输出结果为:“int: 8” B.程序可以编译运行,输出结果为:“long: 8”
C.程序有编译错误,因为两个method()方法必须定义为静态(static)的 D.程序可以编译运行,但是没有输出
6. 能作为类及其成员的修饰符是( )。
A.interface B.class C.protected
D.public
7. 下列方法定义中,方法头不正确的是( )。
A.public static x(double a){…} B.public static int x(double y){…}C.void x(double d){…}
D.public int x(){…} 8. 构造方法在( )时被调用。
A.类定义时
B.使用对象的变量时 C.调用对象方法时
D.创建对象时
9. 下列哪个类声明是正确的( )。
A.public abstract class Car{…} B.abstract private move(){…} C.protected private number;
D.abstract final class H1{…}
10. 下列不属于面向对象程序设计的基本特征的是( )。
10
A.抽象 B.封装 C.继承
D.静态
11. 请看下面的程序段 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 ){
//doing the same as two arguments version if constructer }
下面那个选项可以添加到// doing the same??处( )
A.Person(n,a) B.this(Person(n,a)) C.this(n, a)
D.this(name.age)
12. 请看下面的程序段 class Test{
private int m;
public static void fun(){ //some code }
}
方法fun()如何来访问变量m( )
A.将private int m 改成protected int m B.将private int m 改成public int m C.将private int m 改成static int m D.将private int m 改成int m 13. 有一个类A,对于其构造函数的声明正确的是( )。
A.void A(int x){?} B.public A(int x){?} C.A A(int x){?}
D.int A(int x){?}
14. 请看下面的程序段 public class Test{
long a[]=new long[10];
pubic static void main(String args[]){
System.out.println(a[6]); }
}
哪一个选项是正确的( )。
A.不输出任何内容
B.输出0
C.当编译时有错误出现 D.当运行时有错误出现 15. 关键字( )表明一个对象或变量在初始化后不能修改。
A.extends B.final C.this
D.finalize
16. 声明为static的方法不能访问( )类成员。
11
A.超类 C.非static
17. 定义类A如下: class A{
int a,b,c;
public void B(int x,int y, int z){ a=x;b=y;c=z;} }
下面对方法B的重载哪些是正确的( )。
B.子类
D.用户自定义类
A.public void A(int x1,int y1, int z1){ a=x1;b=y1;c=z1;} B.public void B(int x1,int y1, int z1){ a=x1;b=y1;c=z1;} C.public void B(int x,int y){ a=x;b=y;c=0;} D.public B(int x,int y, int z){ a=x;b=y;c=z;}
18. 编译运行下面的程序,结果是( )。 public class A{
public static void main(String args[]){
B b=new B(); b.test(); }
void test(){
System.out.print(“A”); } }
class B extends A{ void test(){
super.test();
System.out.print(“B”); } }
A.产生编译错误
19. 已知类关系如下: Class Employee{}
Class Manager extends Employee{} Class Director extends Employee{} 则下列语句正确的是:( )。
B.代码可以编译运行,并输出结果:AB
C.代码可以编译运行,但没有输出 D.编译没有错误,但会产生运行时异常
A.Employee e=new Manager(); C.Director d =new Employee ();
B.Director d=new Manager(); D.Manager m=new Director ();
20. 接口是Java面向对象的实现机制之一,以下说法正确的是( )。
A.Java支持多重继承,一个类可以实现多个接口 B.Java只支持单重继承,一个类可以实现多个接口 C.Java只支持单重继承,一个类可以实现一个接口
12