搜索
您的当前位置:首页正文

java面向对象程序设计科目考试卷及答案 (1)

来源:意榕旅游网
 - !

_______ ______________名_姓__ _ _ 线 _ ___________订____号_考_ _ _ 装 _ _______________级_班_ _ _ _ _ _ _ _ _ _ _ _ _1

_ _ __安徽财贸职业学院2011—2012学年第二学期 __《Java面向对象程序设计》期末试卷(B卷)

__适用班级:软件1101

__ _ 题号 一 二 三 四 总分 __ 得分 ___得分 评卷人 一、单选题(每小题1分,共30分) __

_

_1.在MyEclipse中,( )视图可以将项目中包含的文件及层次结构展示出来。 _A) Package B)Declaration C)Navigator D) Console __2.下列标识符中,正确的是( )。 _A)class B) 123_rr C) _lei D) test&12 __3.下列的( )选项可以正确用以表示八进制值8。 _A)0x8 B)0x10 C)08 D)010 __4.以下哪个不是Java的原始数据类型( ) _A) int B) boolean C) float D) Char __5.下列有关Java布尔类型的描述中,正确的是( ) _A)一种基本的数据类型,它的类型名称为boolean __B)用int表示类型

_C)其值可以赋给int类型的变量 __D)有两个值,1代表真,0代表假

_6.在Java中,不属于整数类型变量的是( ) _A) double B) long C) int D) byte __7.以下do-while语句构成的循环执行次数是( )。 _int k=0;

__do { ++k ;}while(k<1);

_A) 一次也不执行 B) 执行1次 C) 无限次 D) 有语法错误,不能执__行

_8.表达式(1/0<1)&& (12==0) 的值为( )。

__A) true B) false C) 0 D) 运行时抛出异常 _9.以下( )表达式不可以作为循环条件 __A) i=5 B )i<3 C) count==i D) bEqual=str.equals(\"q\") _10.下列数组初始化正确的是( ) __A) int score[5] = {90,12,34,77,56}; _B) int[5] score = new int[];

_____ - !

C) int[] score = new int[5]{90,12,34,77,56}; D) int score[] = new int[]{90,12,34,77,56}; 11.若有定义:byte[] x={11,22,33,-66};

其中0≤k≤3,则对x数组元素错误的引用是( ) A) x[5-3] B) x[k] C) x[k+5] D) x[0] 12.以下代码的输出结果是()。

public static void main(String[] args){

for(int i=1;i<=10;i++){ if(i%2==0||i%5==0){ continue; }

System.out.print(i + \"\\"); }

} A) 1 B) 1 3 4 C) 1 3 5 7 9 D) 1 3 7 9 13.下列( )选项的java源文件代码片段是不正确的。 A) package testpackage; B) import java.io.* ; public class Test{} package testpackage; public class Test{} C) import java.io.* ; D) import java.io.* ; class Person{} import java.awt.* ; public class Test{} public class Test{}

14.为了在当前程序中使用包ch4中的类,可以使用的语句是( )。 A) import ch4.*; B) package ch4.*; C) import ch4; D) package ch4; 15.下面说法中不正确的是:( )

A) 类是对象的抽象,对象是类的实例 B) 类是组成java程序的最小的单位 C) java语言支持多继承 D) java一个程序中只能有一个public类 16.对于下面的不完整的类代码,下面表达式中,( )可以加到构造方法中的横线处。

class person{

String name,department; public void person(String n){ name=n; }

public person(String n,String d){ _______________ department=d; }

}

person p = new person(“jim”);

person p = new person(“jim”,”jsjx”); A)person(n) B)this(person(n)) C)this(n) D)this(n,a); 17.构造方法何时被调用?( ) A)类定义时 B)创建对象时 C)调用对象方法时 D)使用对象的变量时 18.定义一个类名为“MyClass.java”的类,并且该类可被一个工程中的所有类访问,那么2

- !

该类的正确声明应为 ( )。

(A)private class MyClass extends Object (B)class MyClass extends Object (C)public class MyClass

(D)private class MyClass extends Object 19.方法重载是指 ( )

(A)两个或两个以上的方法取相同的方法名,但形参的个数或类型不同

(B)两个以上的方法取相同的名字和具有相同的参数个数,但形参的类型可以不同 (C)两个以上的方法名字不同,但形参的个数或类型相同

(D)两个以上的方法取相同的方法名,并且方法的返回类型相同

20.如果编写一个main()方法调用HelloAccp类的show()方法,其运行结果是( )。

public class HelloAccp{

int a=100,b=50; public void avg(){ float c=(a+b)/2; }

public void show(){

System.out.println(\"平均值为:“ + c); }

}

A)存在错误,提示:无法解析c B)平均值为:75 C)平均值为:75.0

D)存在错误,提示:无法将数据类型int转换为float 21.对于下列代码: 1) class Person {

2) public void printValue(int i, int j) {//... } 3) public void printValue(int i){//... }

4) }

5) public class Teacher extends Person { 6) public void printValue() {//... } 7) public void printValue(int i) {//...} 8) public static void main(String args[]){ 9) Person t = new Teacher(); 10) t.printValue(10); 11) } 12) }

第10行语句将调用哪行语句?( ) A) line 2 B) line 3 C) line 6 D) line 7 22.阅读下面代码:

class parent{

protected int addvalue(int a,int b){ int s; s=a+b; return s; }

}

class child extends parent{ } 3

- !

若要在child类中对addvalue方法进行重写,下面对于child类中的addvalue方法头的描述()是正确的。

A)int addvalue(int i,int j) B)void addvalue() C)void addvalue(double i) D)public int addvalue(int a,int b) 23.下列哪个类声明是正确的( ) A) abstract final class H1{…} B) abstract private move(){…} C) protected private number; D) public abstract class Car{…} 24.Java中所有类的父类是 A)Father B)Lang C)Exception D)Object 25.编译如下Java代码,输出结果是()。

class Base{

public void method(){

System.out.print(\"Base method\"); }

}

class Child extends Base{ public void method(){

System.out.print(\"Child method\"); }

}

class Sample{

public static void main(String[] args){ Base base=new Child(); base.method(); }

}

A) Base method B) Child method C) Base method Child method D) 编译错误

26.下列Java代码中Test类中的四个输出语句的输出结果依次是()。

class Person{

String name=\"person\"; public void shout(){

System.out.print(name); }

}

class Student extends Person{ String name=\"student\"; String school=\"school\";

}

class Test{

public static void main(String[] args){ Person p=new Student();

System.out.print(p instanceof Student); System.out.print(p instanceof Person); System.out.print(p instanceof Object); System.out.print(p instanceof System); }

}

A) true、false、true、false B) false、true、false、true 4

- !

C) true、true、true、编译错误 D) true、true、false、编译错误 27.以下关于接口的说法中,正确的是()。

A) 接口中全部方法都是抽象方法,方法可以是任意访问权限

B) 接口中属性都是使用public static final修饰,没有显式赋值将使用默认值 C) 接口可以有构造方法

D) 接口表示一种约定,接口表示一种能力,接口体现了约定和实现相分离的原则 28.给定如下Java代码,可以填入横线处的语句是()。

public interface Constants{ int MAX = 50; int MIN = 1;

}

public class Test{

public static void main(String[] args){ _________________ }

}

A) Constants con = new Constants(); B) Constants.MAX = 100; C) int i = Constants.MAX-Constants.MIN ; D) Constants.MIN>0; 29.请问所有的异常类皆继承哪一个类?( )。 A)java.io.Exception B)java.lang.Throwable C)java.lang.Exception D)java.lang.Error 30.对于catch子句的排列,下列哪种是正确的( ) A)父类在先,子类在后 B)子类在先,父类在后 C)有继承关系的异常不能在同一个try程序段内 D)先有子类,其他如何排列都无关 二、填空题(每空2分,共20分) 得分 评卷人

1.Java有___________、____________和JavaME三个版本。

2.Java 源程序文件编译后产生的文件称为____________文件,其扩展名为___________。 3.面向对象编程的三大特性是____________、_____________和多态。

4.___________方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法必须在抽象类之中定义。___________方法是不能被当前类的子类重新定义的方法。

5.子类必须通过_______关键字调用父类有参数的构造函数。

6.在Java程序中,通过类的定义只能实现单重继承,但通过____________ 的定义可以实现多重继承关系。

三、阅读理解题(每题4分,共20分) 得分 评卷人

5

- !

1.下列程序段的运行结果为______________。 int a=1; while(a<5){

switch(a){

case 0:

case 3:a=a+1; case 1:

case 2:a=a+2; } }

System.out.print(a);

2.下列程序段的运行结果为______________。 class test1{

public static void main(String args[]) { int y,x=1,total=0; while(x<=3){ y=x*x;

System.out.println(y); total+=y; ++x; }

System.out.println(\"total is \"+total); }

}

3.下列程序段的运行结果为______________。 class Q1{

public static void main(String args[ ]){ double d=10;

Dec dec=new Dec( ); dec.decrement(d); System.out.println(d); } }

class Dec{

public void decrement(double decMe){ decMe = decMe -5;

}

}

4.下列程序段的运行结果为______________。 public class abc{

public static void main(String args[ ]){

SubSubClass x = new SubSubClass(10 , 20 , 30);

x.show(); } }

class SuperClass{

int a,b;

SuperClass(int aa , int bb){

a=aa; b=bb; }

void show( ) {

System.out.println(\"a=\"+a+\"\\nb=\"+b); }

} 6

- !

class SubClass extends SuperClass{

int c;

SubClass(int aa,int bb,int cc){

super(aa,bb); c=cc;

} }

class SubSubClass extends SubClass {

int a;

SubSubClass(int aa,int bb,int cc) {

super(aa,bb,cc); a=aa+bb+cc;

}

void show(){

System.out.println(\"a=\"+a+\"\\nb=\"+b+\"\\nc=\"+c); }

}

5.下列程序段的运行结果为______________。 public class Test{

public static void foo(int i){ try{

if(i==1){

throw new Exception(); }

System.out.print(\"1\"); }catch(Exception e){

System.out.print(\"2\"); }finally{

System.out.print(\"3\"); }

System.out.print(\"4\"); }

public static void main(String[] args){ foo(1); }

}

四、编程题(共30分) 得分 评卷人

1.(每空3分,共9分)分析下列程序,把程序补充完整。 class point{ //定义坐标类

private int x,y;

public point(int a,int b){

x=a; y=b; } }

class rec _____【1】_____{ //定义长方形类

int length,width;

public rec(int a1,int b1,int l,int w){

_______【2】_______;

length=l;width=w;

} } 7

- !

class test{

public static void main(String args[]){

//定义名为r1的对象同时初始化坐标为0,0,长度为10,宽度为20

___________【3】____________; } } 2.(7分)将一组乱序的字符进行升序和降序排列,并分别输出。输出格式如图1所示。

图1

3.(14分)汽车租赁公司出租多种车辆,车型和租金情况如下表所示。编写程序实现租赁价格的计算。 车型 日租费 (元/天) 别克商务舱GL8 600 轿车 宝马550i 500 别克林荫大道 300 客车(金杯、金龙) <=16座 800 >16座 1500 具体要求:车辆分为轿车和客车两大类,它们都继承自抽象类MotoVehicle,并实现其抽象方法calRent()。请根据下面给出的类图分别创建三个类,并在测试类TestRent中实现车辆的租赁。租赁过程如图2所示。

Car MotoVehicle -type:String

-no:String -brand:String + MotoVehicle () +MotoVehicle (no,brand) +getNo():String +getBrand():String +calRent():int +Car(no,brand,type) +getType():String + calRent():int Bus -seatCount:int +Bus(no,brand,seatCount) +getSeatCount ():String +calRent():int 8

- !

_______ ______________名_姓__ _ _ 线 _ ___________订____号_考_ _ _ 装 _ _______________级_班_ _ _ _ _ _ _ _ _ _ _ 9

_ _ _ _ _ 安徽财贸职业学院

2011—2012学年第二学期

__《Java面向对象程序设计》期末试卷答题卡(B卷)

__适用班级:软件1101

__ _题号 一 二 三 四 总分 __得分 _

__得分 评卷人 一、单选题(每小题1分,共30分)

__ _

_ __1 2 3 4 5 6 7 8 9 10 _ __11 12 13 14 15 16 17 18 19 20 _ __21 22 23 24 25 26 27 28 29 30 _ __ _得分 评卷人 二、填空题(每空2分,共20分) __ __

__1.__________________ ____________________ __2.__________________ ____________________ _3.__________________ ____________________ __4.__________________ ____________________ __5.__________________ 6.__________________ __ __得分 评卷人 三、阅读理解题(每题4分,共20分) __

__

_1.__________________ 2.__________________ __

_3.__________________ 4.__________________ __

_____ - !

5.__________________

四、编程题(共30分)

1.(每空3分,共9分)

【1】_______________________ 【2】_______________________

【3】_____________________________________ 2.(7分)

得分 评卷人 3.(14分)

10

安徽财贸职业学院2011—2012学年度第二学期 《Java面向对象程序设计》期末试卷答案(B卷)

适用班级:软件1101

一、单选题

1 2 3 4 5 6 7 8 9 10

C C D D A A B B A D

11 12 13 14 15 16 17 18 19 20

C D B A C C B C A A

21 22 23 24 25 26 27 28 29 30

D D D D B C D C C B

二、填空题

1.JavaSE JavaeE 2.字节码 .class 3.封装 继承

4.抽象(或abstract) final 5.super 6.接口 三、阅读理解题

1.6 3.10.0 2.1 4.a=60 4 b=20 9 c=30 Totle is 14 5.234

四、编程题

1.【1】entends Point 【2】super(a1,b1) 【3】Rec r1=new Rec(0,0,10,20) 2.import java.util.Arrays; public class CharsSort {

public static void main(String[] args) {

char[] chars = new char[]{'a','c','u','b','e','p','f','z'}; System.out.print(\"原字符序列:\"); for(int i = 0; i < chars.length; i++){ System.out.print(chars[i] + \" \"); } Arrays.sort(chars); //对数组进行升序排序 System.out.print(\"\\n升序排序后:\"); for(int i = 0; i < chars.length; i++){ System.out.print(chars[i] + \" \"); } System.out.print(\"\\n逆序输出为:\"); for(int i = chars.length-1; i >= 0; i--){ System.out.print(chars[i] + \" \"); } }

}

3.public abstract class MotoVehicle { private String no;// 汽车牌号

1

private String brand;// 汽车品牌 public MotoVehicle() { }

public MotoVehicle(String no, String brand) { this.no = no; this.brand = brand; }

public String getNo() { return no; }

public String getBrand() { return brand; }

public abstract int calRent(int days); }

public final class Car extends MotoVehicle { private String type;// 汽车型号 public Car() { } public Car(String no, String brand, String type) { super(no, brand); this.type = type; } public String getType() { return type; } public void setType(String type) { this.type = type; } public int calRent(int days) { if (\"1\".equals(type)) {// 代表550i return days * 500; } else if (\"2\".equals(type)) {// 2代表商务舱GL8 return 600 * days; } else { return 300 * days; } }

}

public final class Bus extends MotoVehicle { private int seatCount;// 座位数 public Bus() { }

public Bus(String no, String brand, int seatCount) { super(no, brand); this.seatCount = seatCount; }

public int getSeatCount() { return seatCount; }

public void setSeatCount(int seatCount) { this.seatCount = seatCount; 2

3

}

public int calRent(int days) { if (seatCount <= 16) { return days * 800; } else { return days * 1500; } } }

import java.util.Scanner; public class TestRent {

public static void main(String[] args) { String no,brand,mtype,type; int seatCount,days,rent; Car car; Bus bus; Scanner input = new Scanner(System.in); System.out.println(\"欢迎您来到汽车租赁公司!\"); System.out.print(\"请输入要租赁的天数:\"); days=input.nextInt(); System.out.print(\"请输入要租赁的汽车类型(1:轿车 2、客车):\"); mtype = input.next(); if(\"1\".equals(mtype)){ System.out.print(\"请输入要租赁的汽车品牌(1、宝马 2、别克):\"); brand=input.next(); System.out.print(\"请输入轿车的型号 \"); if(\"1\".equals(brand)) System.out.print(\"(1、550i):\"); else System.out.print(\"(2、商务舱GL8 3、林荫大道)\"); type=input.next(); no=\"京BK5543\";//简单起见,直接指定汽车牌号 System.out.println(\"分配给您的汽车牌号是:\"+no); car =new Car(no,brand,type); rent=car.calRent(days); } else{ System.out.print(\"请输入要租赁的客车品牌(1、金杯 2、金龙):\"); brand=input.next(); System.out.print(\"请输入客车的座位数:\"); seatCount=input.nextInt(); no=\"京AU8769\";//简单起见,直接指定汽车牌号 System.out.println(\"分配给您的汽车牌号是:\"+no); bus=new Bus(no,brand,seatCount); rent=bus.calRent(days); } System.out.println(\"\\n顾客您好!您需要支付的租赁费用是\"+rent+\"。\"); } }

因篇幅问题不能全部显示,请点此查看更多更全内容

Top