《面向对象程序设计(java)》复习题(三)

一、单项选择题

1、如下哪个是Java中的标识符( D

  A、public        Bsuper             C3number     Dwidth

2、如下哪个是Java中的标识符(  A  )

Afieldname    Bsuper          C3number     D#number

3、已知如下定义:String s = "story"; 下面哪个语句不是合法的(  C  )

As += "books";                           Bs = s + 100;

Cint len = s.length;                     DString t = s + “abc”;

4、如下哪个是Java中有效的关键字( C )

Aname            Bhello             Cfalse            Dgood

5、下面的代码段执行之后count的值是什么(   D   )

    int count = 1;

    for (int i = 1; i <= 5; i++) {

       count += i;

    }

    System.out.println(count);

A5            B1                 C15               D16

6、定义一个类,必须使用的关键字是(  B  )

Apublic           Bclass             Cinterface       Dstatic

7、定义一个接口必须使用的关键字是(   C  

Apublic          B、class             Cinterface       Dstatic

8、如果容器组件p的布局是BorderLayout,则在p的下边中添加一个按钮b,应该使用的语句是(  C

       Ap.add(b);                                  Bp.add(b,"North");

       Cp.add(b,"South");                     Db.add(p,"North");

9、声明并创建一个按钮对象b,应该使用的语句是(  A  

AButton b=new Button();          Bbutton b=new button();

CButton b=new b();                    Db.setLabel(“确定”);

10Frame对象默认的布局管理器是(

AFlowLayout                       BBorderLayout     

CCardLayout                       Dnull

11、下列哪一个import命令可以使我们在程序中创建输入/输出流对象( C

Aimport java.sql.*;       //数据库   Bimport java.util.*;

Cimport java.io.*;                  Dimport java.net.*;//代表网络

12、下面哪一个import命令可以为我们提供编写网络应用程序的类( D

Aimport java.sql.*;                     Bimport java.util.*;

Cimport java.io.*;               Dimport java.net.*;

13、如果需要从文件中读取数据,则可以在程序中创建哪一个类的对象( A

AFileInputStream               BFileOutputStream

CDataOutputStream           DFileWriter//文件的写

二、填空题

1、如果将类MyClass声明为public它的文件名称必须是   MyClass.java  才能正常编译。

2Java程序中的单行注释符是(   //   ),多行注释符是(   /*   */  )。

3Java中布尔类型的常量有两种,它们是(  true  )和(  false  )。

4Java中用于定义小数的关键字有两个:(  float     double   ),后者精度高于前者。

5Java中用于两个数相等比较的运算符是:( ==  ),用于不相等比较的运算符是(  < > )。

6、在Java中定义一个字符串类型的变量str的语句是:  String str  ,定义一个具有10个元素的整型数组a的语句是  int [] arr = new int [10] ;        

7、导入mypackage包中的所类的命令是    import mypacka.*;        

8、当声明一个数组int arr[] = new int[5]; 时,这代表这个数组所保存的变量类型是(   int  ),数组名是(  arr  ),数组的大小为(  5     ),数组元素下标的使用范围是(  04  ) 

9、假设x=13y=4,则表达式x%y != 0的值是( true ,其数据类型是( boolean)。

10、异常处理是由(   try )、(  catch  )和finally块三个关键所组成的程序块。

11、以下程序段的输出结果是(三角形

    int x = 5, y = 6, z = 4;

    if (x + y > z && x + z > y && z + y > x)

       System.out.println("三角形");

    else

       System.out.println("不是三角形");

12、下面程序段的执行结果是   6 5 4 3 2   

    int a[] = { 2, 3, 4, 5, 6 };

    for (int i = a.length() - 1; i >= 0; i--)

       System.out.print(a[i] + "");

三、程序阅读题

1以下程序的输出结果为  _  Peter is 17 years old!     __

public class Person {

    String name;

    int age;

    public Person(String name, int age) {

       this.name = name;

       this.age = age;

    }

    public static void main(String[] args) {

       Person c = new Person("Peter", 17);

       System.out.println(c.name + " is " + c.age + " years old!");

    }

}

2以下程序的输出结果为    课程号:101 课程名:ASP 学分:3          

public class Course {

    private String cNumber;

    private String cName;

    private int cUnit;

    public Course(String number, String name, int unit) {

       cNumber = number;

       cName = name;

       cUnit = unit;

    }

    public void printCourseInfo() {

       System.out.println("课程号:" + cNumber + " 课程名:" + cName + " 学分:" + cUnit);

    }

}

class CourseTest {

    public static void main(String[] args) {

       Course c;

       c = new Course("101", "ASP", 3);

       c.printCourseInfo();

    }

}

3以下程序的输出结果为_   汤姆猫体重:20.0        __

public class Tom {

    private float weight;

    private static String name;

    public void setWeight(float weight) {

       this.weight = weight;

    }

    private void out() {

       System.out.println(name + "体重:" + weight + "");

    }

    public static void main(String[] args) {

       Tom.name = "汤姆猫";

       Tom cat = new Tom();

       cat.setWeight(20);

       cat.out();

    }

}

4以下程序的输出结果

姓名:Tom 年龄:15 家庭地址:金水区 电话:66123456 学校:九中                         

    String name, address, tel;

    int age;

    public Father(String name, int age) {

       this.name = name;

       this.age = age;

    }

    void out() {

       System.out.print("姓名:" + name);

       System.out.print(" 年龄:" + age);

    }

    void outOther() {

       System.out.print(" 家庭住址:" + address);

       System.out.print(" 电话:" + tel);

    }

}

class Son extends Father {

    String school;

    public Son(String name, int age) {

       super(name, age);

    }

    void out() {

       super.out();

       super.outOther();

       System.out.println(" 学校:" + school);

    }

    public static void main(String args[]) {

       Son son = new Son("Tom", 15);

       son.address = "金水区";

       son.school = "九中";

       son.tel = "66123456";

       son.out();

    }

}

5下列程序的运行结果是   12345                  

public class MyClass {

    int a[] = { 1, 2, 3, 4, 5 };

    void out() {

       for (int j = 0; j < a.length; j++)

           System.out.print(a[j] + "");

    }

    public static void main(String[] args) {

       MyClass my = new MyClass();

       my.out();

    }

}

四、简答题

1简述Java中异常处理的机制?

2什么是继承?

3请简述重载和重写的区别?

五、程序设计题

1按以下要求编写程序

(1) 创建一个Rectangle类,添加widthheight两个成员变量

(2) Rectangle中添加两种方法分别计算矩形的周长和面积

(3) 编程利用Rectangle输出一个矩形的周长和面积

2按以下要求编写程序

(1) 编写Animal接口,接口中声明run() 方法

(2) 定义Bird类和Fish类实现Animal接口

(3) 编写Bird类和Fish类的测试程序,并调用其中的run()方法

  • 1
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 好的,我可以回答这个问题。以下是一个简单的单项选择题标准化考试的C语言程序: #include <stdio.h> int main() { int score = ; // 记录分数 char answer; // 记录答案 // 第一题 printf("1. C语言,下列哪个关键字用于定义常量?\n"); printf("A. const\nB. static\nC. volatile\nD. extern\n"); printf("请输入你的答案(A/B/C/D):"); scanf("%c", &answer); if (answer == 'A' || answer == 'a') { score += 10; } // 第二题 printf("2. 下列哪个函数用于输出字符?\n"); printf("A. printf\nB. scanf\nC. getchar\nD. putchar\n"); printf("请输入你的答案(A/B/C/D):"); scanf(" %c", &answer); // 注意加一个空格,避免读取上一个输入的回车符 if (answer == 'D' || answer == 'd') { score += 10; } // 第题 printf("3. 下列哪个运算符用于取地址?\n"); printf("A. &\nB. *\nC. /\nD. %\n"); printf("请输入你的答案(A/B/C/D):"); scanf(" %c", &answer); if (answer == 'A' || answer == 'a') { score += 10; } // 输出分数 printf("你的得分是:%d\n", score); return ; } 希望这个程序能够帮到你! ### 回答2: 当然可以帮您写一个单项选择题标准化考试的C语言程序。下面是一个简单的示例程序: ```c #include <stdio.h> int main() { // 定义题目数组 char questions[][100] = { "1. C语言是一种什么类型的计算机编程语言?", "2. 下列选项,不属于C语言基本数据类型的是:", // 添加更多题目... }; // 定义选项数组 char options[][4][100] = { {"A. 高级语言", "B. 低级语言", "C. 语言", "D. 汇编语言"}, {"A. int", "B. char", "C. float", "D. string"}, // 添加更多选项... }; // 定义正确答案数组 char answers[] = {'A', 'D'}; // 定义用户答案数组 char userAnswers[100]; int totalQuestions = sizeof(questions) / sizeof(questions[0]); int score = 0; printf("欢迎参加单项选择题标准化考试!\n"); // 循环显示问题并获取用户答案 for (int i = 0; i < totalQuestions; i++) { printf("\n%s\n", questions[i]); for (int j = 0; j < 4; j++) { printf("%s\n", options[i][j]); } printf("请输入您选择的答案(A, B, C, D):"); scanf(" %c", &userAnswers[i]); if (userAnswers[i] == answers[i]) { score++; // 回答正确,得分加一 } } printf("\n考试结束!您的得分是:%d/%d\n", score, totalQuestions); return 0; } ``` 上述程序使用了两个二维字符数组来存储题目和选项,使用一个字符数组来存储正确答案。程序会逐个显示问题,并要求用户输入答案。在用户回答完所有问题后,程序会计算得分并显示在屏幕上。 请注意,该程序只是一个简单示例,仅包含两个问题。如果需要添加更多问题,可以根据示例的格式进行修改和扩展。 ### 回答3: 下面是一个用C语言编写的标准化考试的单项选择题程序的示例: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_QUESTIONS 10 // 定义题目结构体 typedef struct { char question[100]; char options[4][50]; int correctOption; } Question; // 初始化题库 void initializeQuestions(Question *questions) { strcpy(questions[0].question, "What is the capital of France?"); strcpy(questions[0].options[0], "A. Paris"); strcpy(questions[0].options[1], "B. London"); strcpy(questions[0].options[2], "C. Madrid"); strcpy(questions[0].options[3], "D. Rome"); questions[0].correctOption = 0; // 添加更多题目... } // 显示题目并获取用户答案 int displayQuestionAndGetAnswer(Question question) { int answer; printf("%s\n", question.question); for (int i = 0; i < 4; i++) { printf("%s\n", question.options[i]); } printf("Please enter your answer (A/B/C/D): "); char userAnswer; scanf(" %c", &userAnswer); switch (userAnswer) { case 'A': case 'a': answer = 0; break; case 'B': case 'b': answer = 1; break; case 'C': case 'c': answer = 2; break; case 'D': case 'd': answer = 3; break; default: answer = -1; break; } return answer; } // 计算并显示考试结果 void displayResult(int *userAnswers, Question *questions, int numQuestions) { int score = 0; printf("\n----- Exam Results -----\n"); for (int i = 0; i < numQuestions; i++) { if (userAnswers[i] == questions[i].correctOption) { score++; } printf("Question %d: %s\nYour Answer: %s\nCorrect Answer: %s\n\n", i+1, questions[i].question, questions[i].options[userAnswers[i]], questions[i].options[questions[i].correctOption]); } printf("Score: %d/%d\n", score, numQuestions); } int main() { Question questions[MAX_QUESTIONS]; int userAnswers[MAX_QUESTIONS]; int numQuestions = 3; // 题库的题目数量 initializeQuestions(questions); // 获取用户答案 for (int i = 0; i < numQuestions; i++) { printf("\nQuestion %d:\n", i+1); userAnswers[i] = displayQuestionAndGetAnswer(questions[i]); } // 显示考试结果 displayResult(userAnswers, questions, numQuestions); return 0; } ``` 这个程序使用了题目结构体来存储题目和选项的信息。`initializeQuestions`函数用于初始化题库的题目,你可以根据需要添加更多的题目。`displayQuestionAndGetAnswer`函数用于显示题目并获取用户答案。最后,`displayResult`函数用于计算和显示考试结果。 在`main`函数,我们首先调用`initializeQuestions`来初始化题库,然后通过循环调用`displayQuestionAndGetAnswer`函数获取用户的答案,并将答案存储在`userAnswers`数组。最后,我们调用`displayResult`函数来计算和显示考试结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值