【VIP专享】五邑大学2007-2008 JAVA试题B答案
java试卷B答案 (1)

物理与电信工程学院2011—2012学年第(一)学期期末考试《Java程序设计》试卷(B)一、选择题(在每小题的四个备选答案中,选出一个正确答案,并将正确答案的序号填在题干前的括号内。
每小题1分,共20分)(D )1、数组中可以包含什么类型的元素?_____________。
A、int型B、 string型C、数组D、以上都可以(A )2、为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为( )。
A. static void method( )B. public void method( )C. final void method( )D. abstract void method( )(B )3、编译Java Application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为( )。
A..javaB..classC. .htmlD. .exe(D)4、如果类中的成员变量可以被同一包访问,则使用如下哪个约束符?A、 privateB、publicC、protectedD、no modifier(C )5、以下哪个方法用于定义线程的执行体?A、 start()B、init()C、run()D、main()(D )6.MAX_LENGTH是int型public成员变量, 变量值保持为常量100,用简短语句定义这个变量。
A、 public int MAX_LENGTH=100;B、 final int MAX_LENGTH=100;C、 final public int MAX_LENGTH=100;D、 public final int MAX_LENGTH=100.(B )7.下面哪些选项是正确的main方法说明?A、public main(String args[])B、 public static void main(String args[])C、private static void main(String args[])D、void main()(A )8. ,JA V A对象主要属性有________。
全国计算机二级《Java》题库及答案

全国计算机二级《Java》题库及答案1. 信息隐蔽的概念与下述哪一种概念直接相关()。
A. 软件结构定义B. 模块独立性C. 模块类型划分D. 模块耦合度【答案】B2. 下列各选项中,不属于序言性注释的是()。
A. 程序标题B. 程序设计者C. 主要算法D. 数据状态【答案】D 本资料来源公_众.号:文得课堂,更多计算机等级考试题库及视频,上公_众.号:文得课堂查找。
3. 对建立良好的程序设计风格,下面描述正确的是()。
A. 程序应简单、清晰、可读性好B. 符号名的命名只要符合语法C. 充分考虑程序的执行效率D. 程序的注释可有可无【答案】A4. 下列叙述中,不符合良好程序设计风格要求的是()。
A. 程序的效率第一,清晰第二B. 程序的可读性好C. 程序中要有必要的注释D. 输入数据前要有提示信息【答案】A5. 结构化程序所要求的基本结构不包括()。
A. 顺序结构B. GOTO跳转C. 选择(分支)结构D. 重复(循环)结构【答案】B6. 下列选项中不属于结构化程序设计原则的是()。
A. 可封装B. 自顶向下C. 模块化D. 逐步求精【答案】A7. 结构化程序设计的基本原则不包括()。
A. 多态性B. 自顶向下C. 模块化D. 逐步求精【答案】A8. 结构化程序设计主要强调的是()。
A. 程序的规模B. 程序的效率C. 程序设计语言的先进性D. 程序易读性【答案】D9. 结构化程序设计的3种结构是()。
A. 顺序结构,分支结构,跳转结构B. 顺序结构,选择结构,循环结构C. 分支结构,选择结构,循环结构D. 分支结构,跳转结构,循环结构【答案】B10. 结构化程序的三种基本控制结构是()。
A. 顺序、选择和重复(循环)B. 过程、子程序和分程序C. 顺序、选择和调用D. 调用、返回和转移【答案】A 本资料来源公_众.号:文得课堂,更多计算机等级考试题库及视频,上公_众.号:文得课堂查找。
11. 下列能生成Java文档的命令是()。
2007-2008(1)试卷A

江西财经大学07-08学年第一学期期末考试试卷试卷代码: 03874A 课时: 64学时课程名称:面向对象程序设计(双语) 适用对象:选课班试卷命题人 杨 勇试卷审核人 舒 蔚I、Single-Choice (Every question takes 2 points, the total score is 30 points)1、For a complete C++ program, ( ) is the correct statement.A. The program must have a main function.B. The program can have multiple main functions.C. The program must have a main function and other functions.D. The program can have no main function.2、If we define a macro as: #define f(x) x*x, when we calculate f(4+4)/f(2+2), the result is ( ).A. 24B. 8C. 3D. 283、For the following program, when we input: Zhang Bing, ( ) is the output of it.#include<iostream.h>void main(){s[20];charcin>>s;cout<<s<<endl;}A. ZB. ZhangC. BingD. Zhang Bing4、For the function declaration, ( ) is wrong.A. int max( float, float);B. int max( int , int);C. int max( int =4, int);D. int max(int, float =4);5、For the following program, the correct statement is ( ).void main( ){ int n=0;while(n++<=2); cout<<n;}A. The output is 3.B. The output is 4.C. The output is 2.D. The output is 0.6、For overloaded functions statements, ( ) is wrong.A. The name of the functions must have the same name.B. The type of the arguments must be different in the functions.C. They must have the same returning type.D. The number of the arguments can be different in the functions.7、For class description, ( ) is not correct.A. A class can implement data encapsulation.B. A class can have only one constructor.C. A class at least has one constructor and one destructor.D. In a class, the default is private.8、( ) is the characteristic of destructor.A. Destructor can have one or more arguments.B. The name of destructor is different from the name of the class.C. Destructor can be used to free the allocated memory of the program.D. The definition for the destructor must be given in the class.9、For friend function statements, ( ) is right.A. Friend function is the member function.B. Friend function must be public.C. Friend function can only access the public members of the class.D. Friend function can be defined in the class or out of the class.10、For object and class, ( ) is wrong.A. Object is an instance of a class.B. Class is an abstract of objects.C. A class can just have one object.D. The relation likes the variable and its type.11、The following is the class S, the correct definition of function print( ) is ( ).class S{public: void print( );};A. void S::print( ) { }B. S::void print( ) { cout<<1<<endl;}C. void print( ) { cout<<1<<endl;}D. void S::print(int k=1 ) {cout<<k<<endl; }12、The object declaration of the following class A, ( ) is wrong.class A{a;intpublic:A(int x=10) { a=x; }};A. A a1B. A a2(15)C. A a3=5D. A a4( )13. For the following multi-inherit, when we declared an object c1 of C, ( ) will lead to ambiguity. class A { public: int a, b;};class B { public: int a, b;};class C: public A, public B{ public: int a; }A. c1.aB. c1.bC. c1.A::aD. c1.A::b14、( ) is not correct for description of operator overloading function.A. The combination sequence can be changed.B. The number of operands can’t be changed.C. The priority for operators can’t be changed.D. The syntax for operators can’t be changed.15. For the following function, ( ) can be defined as virtual function.A. The static member functions of the class.B. The constructor of the class.C. The destructor of the class.D. The friend functions of the class.II、Questions ( Five questions are given in the following, please answer each of them in short sentences. Each question takes 3 points, the total score is 15 points)1、Please tell the difference between class and object, and show an example and explain it.2、We can use declarations and directives for namespaces, please tell the difference.3、Why do we say the constructor and destructor are special member functions? What is their difference?4、Why do we need to free a pointer after it has been used?5、What’s the purpose of inherit and how can you say that?III、True or False (Three programs are given in the following, for each of them, if it is defined correctly, please mark “√” for it, else please mark “×” and correct them in two methods by method 1 and method 2. Each question takes 5 points, the total score is 15 points)(Note: The state of member data and main function cannot be changed.)1、#include<iostream.h>class Point{public:Point(double xx=0, double yy=0) {X=xx; Y=yy;}double GetX() { return X;}double GetY() { return Y; }private:double X,Y;};double Dist( Point& a, Point& b){double dx=a.X-b.X;double dy=a.Y-b.Y;return sqrt(dx*dx+dy*dy);}void main(){Point p1(3.0, 5.0), p2(4.0, 6.0);double d=Dist(p1, p2);cout<<"The distance is"<<d<<endl; }2、#include <iostream.h>class base{x;intpublic:i)base(intx=i;{cout<<" Constructing x="<<x<<endl; }~base(){ cout<<" Destructing x="<<x<<endl; }voidshow()cout<<"x="<<x<<endl;{}};class derive: public base{inty;d;basepublic:derive(int i,int j,int k):base(i)y=k;{cout<<"Constructing y="<<y<<endl; }~derive(){ cout<<"Destructing y="<<y<<endl; }};void main(){obj(1,2,3);deriveobj.show();}3、#include<iostream.h>class Complex{double re, im;public:complex::complex(double r,double i) :real(r), imag(i){ }friend Complex operator+ (Complex & c){Complex temp;temp.re=re+c.re;temp.im=im+c.im;return temp;}Complex operator * (Complex &c1, Complex &c2 ){Complex temp;temp.re=c1.re*c2.re-c1.im*c2.im;temp.im=c1.re*c2.im+c1.im*c2.re;return temp;}void print() const{cout<<"("<<re<<","<<im<<")"<<endl;}};void main(){Complex c1(1,2), c2(3,4), c3(0,0);c3=c1*c2;c3.print( ) ;}IV、Complete the program (Every question takes 5 points, the total score is 10 points) (Note: one line for only one C++ sentence)1、After the main function, the outputs are as the following:5 10 15Please complete the program.#include <iostream.h>class A{------①-------------a;intpublic:A(int x=0) { a=x;}};class B{-----②----------b;intpublic:B(int x=0) { b=x;}};class C:public A{c;intb1;Bpublic:--------------------③--------------------{-----------------④---------------------}show()void{-----------------⑤---------------------}};void main(){c1(5,10,15);Cc1.show();}2、After the main function, the outputs are as the following: p->B0.display()p->B1.display()p->D1.display()Please complete the program.#include <iostream.h>void main(){B0 b0, *p;b1;B1D1d1;p=&b0;p->display();p=&b1;p->display();p=&d1;p->display();}class B0 {public:---------------------①---------------------------{---------------------②---------------------------}};class B1: public B0 {public:--------------------③--------------------{ -----------------④--------------------- }};class D1: public B1 {public:void display(){ -----------------⑤--------------------- }};V、Read the following programs and write down the running results (Every question takes 5 points, the total score is 15 points)1、Please write down the running results of the following program:#include <iostream>#include <string>using namespace std;class RMB{public:RMB(unsigned int d=100, unsigned int c=100);RMB operator +(RMB&);friend RMB& operator ++(RMB&);void display(){ cout <<(yuan + jf / 100.0) << endl; }private:unsigned int yuan;unsigned int jf;};RMB::RMB(unsigned int d, unsigned int c){ yuan = d;jf = c;while ( jf >=100 ){yuan ++;jf -= 100;}}RMB RMB:: operator+(RMB& s1){ unsigned int jf1 = jf+s1.jf;unsigned int yuan1 = yuan + s1.yuan;RMB result( yuan1, jf1 );return result;}RMB& operator ++(RMB& s){ s.jf ++;if(s.jf >= 100){s.jf -= 100;s.yuan++; }return s;}void main(){RMB d1(75, 42);RMB d2(28, 61);RMB d3;d3 = d1 + d2;++d3;d3.display();}2、Please write down the running results of the following program: #include<iostream.h>void func();int n=2;void main( ){int a=2, b=5;cout<<"a="<<a<<", b="<<b<<", n="<<n<<endl;func();cout<<"a="<<a<<", b="<<b<<", n="<<n<<endl;func();}void func(){static int a=2;int b=5;a++; b+=5;n+=12;cout<<"a="<<a<<", b="<<b<<", n="<<n<<endl;}3、Please write down the running results of the following program: #include <iostream.h>class StudentID{ public:StudentID(int id){ value=id;cout<<"Assigning student id,"<<value<<endl;}~StudentID(){cout<<"Destructing ID,"<<value<<endl;}protected:int value;};class student{ public:student(char * pName="no name", int ssID=9800):id(ssID) { cout<<"Constructing student,"<<pName<<endl;}protected:StudentID id;};void main( ){student t("Jenny");student s("Jack", 9001);}VI、Programming (The question takes 15 points)The following is a class structure, which includes base classes and derived classes. Please design an optimal program to describe it and give a main function to show the result. Requirement: in all the classes, constructors must be used; after the main function, void main( ) {D0 d; d.fund(); }, the results should be:B0 ConstructorB1 ConstructorB2 ConstructorD0 ConstructorDisplay D0。
2007—2008年全国计算机等级考试二级C语言真题及参考答案

2007年9月全国计算机等级考试二级C语言真题及参考答案一、选择题((1)-(10)每题2分,(11)-(50)每题1分.共60分))下列各题A)、B)、C)、D)四个选项中,只有一个是正确的,请将正确选项涂写在答题卡上,答在试卷上不得分。
(1)软件是指A)程序 B)程序和文档C)算法加数据结构 D)程序、数据和相关文档的集合(2)软件调试的目的是A)发现错误 B)改正错误C)改善软件的性能 D)验证软件的正确性(3)在面向对象方法中,实现信息隐蔽是依靠A)对象的继承 B)对象的多态C)对象的封装 D)对象的分类(4)下列叙述中,不符合良好程序设计风格的是A)程序的效率第一,清晰第二 B)程序的可读性好C)程序中有必要的注释 D)输入数据前要有提示信息(5)下列叙述中正确的是A)程序执行的效率与数据的存储结构密切相关B)程序执行的效率只取决于程序的控制结构C)程序执行的效率只取决于所处理的数据量D)以上三种说法都不对(6)下列叙述中正确的是A)数据的逻辑结构与存储结构必定是一一对应的B)由于计算机存储空间是向量式的存储结构,因此,数据的存储结构一定是线性结构C)程序设计语言中的数组一般是顺序存储结构,因此,利用数组只能处理线线结构D)以上三种说法都不对(7)冒泡排序在最坏情况下的比较次数是A)n(n+1)/2 B)nlog2n C)n(n-1)/2 D)n/2(8)一棵二叉树中共有70个叶子结点与80个度为1的结点,则该二叉树中的总结点数为A)219 B)221 C)229 D)231(9)下列叙述中正确的是A)数据库系统是一个独立的系统,不需要操作系统的支持B)数据库技术的根本目标是要解决数据的共享问题C)数据库管理系统就是数据库系统D)以上三种说法都不对(10)下列叙述中正确的是A)为了建立一个关系,首先要构造数据的逻辑关系B)表示关系的二维表中各元组的每一个分量还可以分成若干数据项C)一个关系的属性名表称为关系模式D)一个关系可以包括多个二维表(11)C语言源程序名的后缀是A).exe B).C C).obj D).cp(12)可在C程序中用做用户标识符的一组标识符是A)and B)Date C)Hi D)case_2007 y-m-d Dr.Tom Bigl(13)以下选项中,合法的一组C语言数值常量是A)028 B)12. C).177 D)0x8A. 5e-3 OXa23 4c1.5 10,000-0xf 4.5e0 Oabc 3.e5(14)以下叙述中正确的是A)C语言程序将从源程序中第一个函数开始执行B)可以在程序中由用户指定任意一个函数作为主函数,程序将从此开始执行C)C语言规定必须用main作为主函数名,程序将从此开始执行,在此结束D)main可作为用户标识符,用以命名任意一个函数作为主函数(15)若在定义语句:int a,b,c,*p=&c;之后,接着执行以下选项中的语句,则能正确执行的语句是A)scanf("%d",a,b,c); B)scanf("%d%d%d",a,b,c);C)scanf("%d",p); D)scanf("%d",&p);(16)以下关于long、int和short类型数据占用内存大小的叙述中正确的是A)均占4个字节 B)根据数据的大小来决定所占内存的字节数C)由用户自己定义 D)由C语言编译系统决定(17)若变量均已正确定义并赋值,以下合法的C语言赋值语句是A)x=y==5; B)x=n%2.5; C)x+n=I; D)x=5=4+1;(18)有以下程序段int j; float y; char name[50];scanf("%2d%f%s",&j,&y,name);当执行上述程序段,从键盘上输入55566 7777abc后,y的值为A)55566.0 B)566.0 C)7777.0 D)566777.0(19)若变量已正确定义,有以下程序段i=0;do printf("%d,",i);while(i++);printf("%d\n",i)其输出结果是A)0,0 B)0,1 C)1,1 D)程序进入无限循环(20)有以下计算公式若程序前面已在命令中包含math.h文件,不能够正确计算上述公式的程序段是A)if(x>=0) y=sqrt(x); B)y=sqrt(x)else y=sqrt(-x); if(x<0) y=sqrt(-x);C)if(x>=0)y=sqrt(x); D)y=sqrt(x>=0?x:-x);If(x<0)y=sqrt(-x);(21)设有条件表达式:(EXP)?i++;j--,则以下表达式中(EXP)完全等价的是A)(EXP= =0) B)(EXP!=0) C)(EXP= =1) D)(EXP!=1)(22)有以下程序#includemain(){int y=9;for( y>0;y--)if(y%3= =0) printf("%d",--y);}程序的运行结果是A)741 B)963 C)852 D)875421(23)已有定义:char c; ,程序前面已在命令行中包含ctype.h文件,不能用于判断c 中的字符是否为大写字母的表达式是A)isupper(c) B)’A’<=c<=’Z’C)’A’<=c&&c<=’Z’ D)c<=(‘2’-32)&&(‘a’-32)<=c(24)有以下程序#includemain(){int i,j,m=55;for(i=1;i<=3;i++)for(j=3;j<=i;j++) m=m%j;printf("%d\n",m);}程序的运行结果是A)0 B)1 C)2 D)3(25)若函数调用时的实参为变量时,以下关于函数形参和实参的叙述中正确的是A)函数的实参和其对应的形参共占同一存储单元B)形参只是形式上的存在,不占用具体存储单元C)同名的实参和形参占同一存储单元D)函数的形参和实参分别占用不同的存储单元(26)已知字符’A’的ASCⅡ代码值是65,字符变量c1的值是’A’,c2的值是’D’。
Java试卷 以及一些答案哟

希望对你的考试有所帮助。
参考答案一、选择题ADADDDAACDCBCABBCBCA二、填空题1. import java.io.*;2. 字节流和字符流3. 标准输出设备和标准错误设备4. File5. FileNotFoundException6. 成员函数和成员变量7. throws三、写出下列程序的运行结果1. 结果为( 6,5 )( 6,7 )2. 结果为(A---B---C)3. 输出结果是:FatherClass.value=100ChildClass value=200200100四、程序设计1. public class Test{public static void main(String args[]){ int a[]={1,4,5,3,2,0};int i,j;for (i=0;i<5;i++)for (j=0;j<5-i;j++)if(a[j]>a[j+1]){int t;t=a[j];a[j]=a[j+1];a[j+1]=t;}for(i=0;i<a.length;i++)System.out.println(a[i]+" ");}}2. class Student {String name="湖南****学院";int sNum=888888;String sex="男";String birth="1988/08/08";String sname;int Score;void setName(String a){sname=a;}void setScore(int b){Score=b;}void show(){System.out.println("所在学校:"+name);System.out.println("学号:"+sNum);System.out.println("性别:"+sex);System.out.println("生日:"+birth);System.out.println("姓名:"+sname);System.out.println("成绩:"+Score);}}class Undergraduate extends Student{String department;String major;void setDeparment(String c){department=c;}void setMajor(String d){major=d;}void show1(){super.show();System.out.println("系部:"+department); System.out.println("专业:"+major);}}class Student{public static void main(String arg[]){Student A=new Student();Undergraduate B=new Undergraduate();B.setName("许翼");B.setScore(95);B.setDeparment("信息工程系");B.setMajor("计算机网络");B.show1();}}3. import java.awt.*;public class TestCenterPanel {public static void main(String args[]) {new MyFrame3(300,300,600,400,Color.BLUE);}}class MyFrame3 extends Frame{//private Panel p;MyFrame3(int x,int y,int w,int h,Color c){super("FrameWithPanel");setLayout(null);setBounds(x,y,w,h);setBackground(c);Panel p = new Panel(null);p.setBounds(w/4,h/4,w/2,h/2);p.setBackground(Color.pink);add(p);setVisible(true);}}二、填空(每空1.5分,共15分)1.在编写Java application程序时,若需要使用到标准输入输出语句,必须在程序的开头写上__import java.io.*;_______________语句。
2007试卷答案c

2007 -2008 学年第 1 学期《高级语言程序设计》期末考试试题参考答案及评分标准一、选择题(每小题2分,共30分)二、填空题(每小题2分,共10分)1.6和42.363.int *p[n]的含义是定义指针数组p,它由n个指向整型数据的指针元素组成,int (*p)[n] 的含义是p为指向含n个元素的一维数组的指针变量。
4.*p>*s5.4,F三、程序阅读题(每小题6分,共30分)1.0B2B4B每个结果1分,如果格式不对扣1分。
2.123789每个结果1分,如果格式不对扣1分。
3.0.000000-1.0000000.5000000.2000000.12500010.000000每个结果1分,如果格式不对扣1分。
4.ABFGKLPCDHYZ每个结果1分,如果格式不对扣1分。
5.□□7□□17□□17□代表空格,每个结果1分,如果格式不对扣1分。
四、编程题(每小题10分,共30分)1.循环实现的小程序:#include<stdio.h>void main(){int i,sum;for (i=1,sum=0; i<=100; i++) (2分)sum+=i; (4分)printf("the sum is %d\n",sum);} (5分)递归实现的小程序:#include<stdio.h>int f(int n){int ff;if (n==1) ff=1; (1分)else ff=f(n-1)+n; (2分)return(ff); (3分)}void main(){printf("the sum is %d\n",f(100));} (5分)每个小程序5分。
2.#include<stdio.h>void factor(int n){int i;for (i=1; i<n; i++) (2分)if (n%i==0) printf("%d,",i);} (4分)void main(){int i,a[10];for(i=0; i<10; i++)scanf("%d",&a[i]); (5分)for (i=0; i<10; i++) (7分){printf("the factors of %d are: ",a[i]);factor(a[i]);printf("\n");} (10分)}3.#include <stdio.h>void main(){struct student{int num;char name[20];int score[3];}stu[10]; (2分)int i,k=0;float ave,high=0;for (i=0; i<10; i++)scanf("%d,%d,%d,%d,%s",&stu[i].num,&stu[i].score[0],&stu[i].score[1],&stu[i].scor e[2],stu[i].name); (4分)for (i=0; i<10; i++) (5分){ave=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0; (6分)if (ave>high){high=ave;k=i;}} (9分)printf("NO.:%d name:%s score:%d,%d,%d average:%f\n", stu[k].num, stu[k].name, stu[k].score[0], stu[k].score[1], stu[k].score[2], high); (10分)}。
[VIP专享]《JAVA语言程序设计》期末考试试题及答案
方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法
5、
。ห้องสมุดไป่ตู้
和
4、若 x = 5,y = 10,则 x < y 和 x >= y 的逻辑值分别为
。
3、设 x = 2 ,则表达式 ( x + + )/3 的值是
字节内存空间。
用
字节内存空间,这样,无论是中文字符还是英文字符,都是占
用
占
2、在 Java 的基本数据类型中,char 型采用 Unicode 编码方案,每个 Unicode 码
。
和
、
1、开发与运行 Java 程序需要经过的三个主要步骤为
int level(BinTreeNodlesevt}r*Beutsl,icnBt(rtrTuiontrcaoTetgtert,_eyapNnpetg)oy;oeN_pddinoeeodtd;fde*esreafc*ttrphsB*au{l)ti;cilrn/duh/tT;ciB/lr/tdo1eiTt;u1ea//NcnrNgoto_loiu(fdn(dtnbe*oetpivdlt{(roe(e}TbidpEititrcfrl(ero!-pbmu>tintrTvritgaey-l(>hlpbulteeie,rtrf=xdt)e,=apr{xkextta,)rt;ru{;k,kr)sd+n;tra+;u1t;ac}0txyBpieTNxv},ooidi{ndet&m*lkac)hi}nil(de)}l;s/e/ js+tr}+uj;cBf+BtoB.+Bid.r.L(;+adikTe+taanN=;t[agojB]e[tdkh=l.se+L+eA1e*+]nr.i;dfc=g(d.-[d;{aiB]1a/it;f/a.;t(dkaA[}ia[]>.kBtdB<}=a];aii.T[BLjt+;aNke.+d[Loni;-]aed-g>t)netahg,B[jt*]+h.)wBd+]{avhi;T=otilareiAedi[n(Be.i{dtm;.<Laive=etAoarngi.0[dLgie],e;jt2Ch=n(o{Sg-0ut9q1h,n/kAL])/t)/iL/[;2s1/e1AtA…aABBmf"…,.S(h+Bq"mniLT6m+irsnet8]e&mhBTen),amidn+dtn&a2Ot*acx(7o10u)n+t)0x{11*ixf=0( nT+o1)d*{ex2i_1f c(+(o!uT2/xn/-*10>tx+l2+cxh=1il;+dnx)o&2/d/h&e=tt_(pn!c:To0o//-duw>1enrw*_c2t/wchx-oi0.1ldu;xon)/)1c*t;cinx6o42.1ucleonfmtt+d/+5ap;t-a5//r7iLg9Cihs4ot8lNuet5nmof9ttdreLp4iegme.=h*ap3tMfAmBol(a[aTrTlit]ex(-;(><i2)nAlccetl[ha0i]}ise=l=ds1,0}A…Tc;[yoine2pu<-nT6ein=-yH>12tp)(]Te;v;enn[Co1-A-ti1o3m1d[u]nA)pHin-[/;in(tv-kL21]ene;]1reyais=A+)nef=[+(t-nm(k1Ta])eAT-p){y>nyA;r-p%c2eh…1iAld3e[2,1]3c,2e1oi20Vn0(u3e=bt×n4i{)n3t1a5)B0);,5b20A}{7,B(2ce[2a150,(l0)ds0cn(a20e,a)]×ie[13j1)1cnr2,a17Af2e0A4,i58g2jtB]b1u(B03}(a5r4,21[En)]06a1B;=07A51([}{0]b937S<A/3)56/HaL([06C0c,sT1b3)]uo[A.>81A0c5u,493]cBn<B0.]=taC5H[L8(0,A1De(4g]k/,Aa5>2EBef0,[)Fy,<]*4C[G)G]b[=2B1,,DHk)g+[]e>,I1AEJy,/[<(,81%C1c]-[8,a5bD1)]C>3C]B,D1<[D1]2Bd62,GFc3E>=41A,V5</1I5EdH475,Gf1231>01+0*J5,91<420G4+0e*30G241,7W1d+*787>13P031,4*9<1L74=41f=0+,515a24953>**/546,17<5+15=0g37413,2*0c5572>/4+517,5<6451*g524,0d+3>956,*5<0315f9+2,3e5W12>14P,12*<3L157g+=56,52f13053>105*693}64*1,{73+80217+9596510*77046873+1*71249264+*9503182+79012*176208590=*2092+8123169831731237*793}W2+531P352L5*0313173+s3T3125158*,21T2052=5,2…915W063…303P5,LTS Tini k1i(2i={a1b,2c,d…e…fg}S0)1,1k10in1i011k11k10n+1kk1Pn21>r+0ikm…00…11+1k0s1=0n11+n21K…ru…snkas1l ns,s=nk,nk a11a121a02K1)aru2s2kaa=2l203*:9(a1i+03/1jA2-03aB(3a131+Aa12=3B+42[…0+]3A…+a3aij1+n3inn149-+iH10-41au+jnfi84+fnm4+16a5B8n+58F1544):52=5706305306.986,2T76:0150,D811:00148110683171,F10ST6:06D413S024H515,1H12:007412101402H*1291u60+22f{f7m4*63a2+n58307*71836+21102*72306+722774*0674128+493}*()4+86*312=513219 5:13/5671(130+7822+6261+p03a1+341352+401143,41)p0=83,21a.8425,913,,p66331:121,0A1a24B13G,,CP4pJ9AD3KG21EHD12AFDaJ3GBH,EPaDHKBApGIBM3J2HEKIF1AJMCKCAEFCMFIIM
二级JAVA机试真题2007年03月
二级JAVA机试真题2007年03月一、基本操作题1. 注意:下面出现的“考生文件夹”均为%USER%。
在考生文件夹下存有文件名为Java_1.java文件,请完善Java_1.java文件,并进行调试,使程序输出结果如下:由于Java_1.java文件不完整,请在注释行“//*********Found*********”下一行语句的下画线地方填入正确内容,然后删除下画线,请勿删除注释行或其他已有语句内容。
存盘时,文件必须存放在考生文件夹下,不得改变原有文件的文件名。
给定源程序://Interest.java//计算复杂利息import java.text.DecimalFormat;import javax.swing.JOptionPane;import javax.swing.JTextArea;public class Java_1{public static void main(String args[]){double amount, principal=10000, rate=.05;DecimalFormat precisionTwo=new DecimalFormat("0.00");//*********Found**********JTextArea outputTextArea=new______(11, 20);outputTextArea.append("年\t存款总计\n");for(int year=1; year<=10; year++){amount=principal*Math.pow(1.0+rate, year);outputTextArea.append(year+"\t"+//*********Found**********precisionTwo.______(amount)+"\n");//*********Found**********JOptionPane.______(null, outputTextArea,"复合利息",RMATION_MESSAGE);System.exit(0);}}答案:JTextArea format showMessageDialog[解答] 第1处:创建文本框对象,需填入JTextArea。
《Java》试卷(B) 排版(补考)
2006~2007学年度第一学期 《JA V A 语言程序设计》期末考试试卷课程代码: 试卷编号:06104-B 命题日期: 2006 年 11 月 15 日答题时限: 120 分钟 考试形式:闭卷笔试一、单项选择题(每小题1.5分,共30分)将答案填在表格内1.下列关于Java 对import 语句规定的叙述中,错误的是( )A 、在Java 程序中import 语句必须有一个B 、在Java 程序中import 语句可以没有C 、在Java 程序中import 语句可以有多个D 、在Java 程序中import 语句必须出现在所有类定义之前 2.以下哪个不是Java 的原始数据类型?A 、booleanB 、IntegerC 、floatD 、double 3.有以下代码片段,运行后,mod 等于多少?Integer num1 = new Integer ("31");Integer num2 = new Integer("4");int mod = num1.intValue() % num2.intValue();A 、3B 、7C 、8D 、7.75 4.以下声明合法的是( )A 、default String s ;B 、abstract final int hyperbolicCosine( )C 、abstract double d ;D 、public final static int w( )5.设x=5 则y=x-- 和y=--x 的结果,使y 分别为( )A 、5,5B 、5,6C 、5,4D 、4,46.有语句String s=”hello world ”; 以下操作哪个是不合法的?A 、int i=s.length();B 、String ts=s.trim();C 、s>>>=3;D 、String t=s+”!”; 7. 编译并运行以下程序,以下描述哪个选项是正确的?1.class A {2. protected String toString() {3. return super.toString(); } }A 、编译通过运行无异常B 、行2出错,不能成功编译C 、不能成功编译,行3出错D 、编译通过但运行时出错 8. 给出如下代码:class Test{private int m;public static void fun() { // ...... } }如何使成员变量m 被函数fun()直接访问?A 、将private int m 改为protected int mB 、将private int m 改为 public int mC 、将private int m 改为 static int mD 、将private int m 改为 int m9. 下列关于构造方法的叙述中错误的是( )A 、Java 语言规定构造方法只能通过new 调用B 、Java 语言规定构造方法没有返回值,不用void 声明C 、Java 语言规定构造方法可以重载D 、Java 语言规定构造方法名与类名必须相同 10.下面的代码有一行是错误的,它是哪一行?1.class StaticFun { 2. static int i = 10;学院(系) _______________专业 ______________选课学号_______________姓名 教学班号_______装订线3.int j;4.static void setValue(int x) {5. j=x;6. System.out.println(" "+ i); } }A、2B、4C、6D、511. 在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数个数、类型或顺序各不相同。
重邮2007~2008学年第1学期Java期末试题
重庆邮电大学2007~2008学年第1学期一、选择题:(每小题2分,共30分)1、哪个关键字可以抛出异常( C)A. transientB. finally ArrayC. throwD. throws2、下面哪个关键字修饰的类不能有子类 ( B )A. finallyB. finalC. finalizeD. abstract3、窗口可以产生WindowEvent事件,实现哪个接口可处理此事件( C )A. FocusListenerB. ComponentListenerC. WindowListenerD. ActionListener4、Java构造函数中使用( A )关键字调用父类的构造函数。
A. superB. parentC. thisD. invoke5、关于类和对象的叙述正确的是:( A )A.Java的类分为两大部分:系统定义的类和用户自定义的类B.类的静态属性和全局变量的概念完全一样,只是表达形式不同C.类的成员至少有一个属性和一个方法D.类是对象的实例化6、以下有关构造方法的说法,正确的是:( A )A.一个类的构造方法可以有多个B.构造方法在类定义时被调用C.构造方法只能由对象中的其它方法调用D.构造方法可以和类同名,也可以和类名不同7、Frame容器的默认布局管理器是( C )A. CardLayoutB. FlowLayoutC. BorderLayoutD. GridLayout8、Panel类在哪个包中?( C )A. java.util C. java.awtB. java.io D. ng9、关于Java中数据类型叙述正确的是:( B )A、整型数据在不同平台下长度不同B.boolean类型数据只有2个值,true和falseC.数组属于简单数据类型D.Java中的指针类型和C语言的一样10、关于Java中异常的叙述正确的是:( D )A.异常是程序编写过程中代码的语法错误B.异常是程序编写过程中代码的逻辑错误C.异常出现后程序的运行马上中止D.异常是可以捕获和处理的11、Paint() 方法使用哪种类型的参数( A )A.GraphicsB. Graphics2DC.StringD. Color12、以下有关类的继承的叙述中,正确的是:(D)A.子类能直接继承父类所有的非私有属性,也可通过接口继承父类的私有属性B.子类只能继承父类的方法,不能继承父类的属性C.子类只能继承父类的非私有属性,不能继承父类的方法D.子类不能继承父类的私有属性13、下面有关类 Demo 的描述正确的有(A)Public class Demo extends Base{Private int count;Public Demo(){System.out.println(“A Demo object has been created”);}Protected void assone(){Count++;}}A.当创建一个 Demo 类的实例对象时, count 的值为 0B.当创建一个 Demo 类的实例对象时, count 的值是不确定的C. Base 类型的对象中可以包含改变 count 值的方法D. Demo 的子类对象可以访问 count14、虽然接口和抽象类不能创建对象,但它们的对象引用仍可指向该类型的对象。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
第 1 页 共 6 页题号一二三四五六七八九十总分得分
一、单项选择题(2分/题,共30分)
1.下列哪些类声明是错误的( D )A、class A B、 public class AC、 abstract class A D、protected class A
2.定义一个接口必须使用的关键字是( C )A、public B、classC、interfaceD、static
3.访问权限是指对象是否可以通过“.”运算符操作自己的变量,或通过“.”运算符使用类中的方法,下列那个不是访问限制修饰符( A )A、static B、public C、private D、ptotected
4.下列描述错误的是( D )A、上转型对象不能操作子类新增的成员变量 B、上转型对象不能操作子类新增的方法C、 上转型对象可以操作子类继承或隐藏的成员变量D、上转型对象不能操作子类重写的方法
5.JFrame对象默认的布局管理器是( B )A、FlowLayoutB、BorderLayoutC、CardLayoutD、null
6.定义类头时能使用的修饰符是( C )。A、 private B、 static C、 abstract D、 protected
7.下列哪一个import命令可以使我们在程序中创建输入/输出流对象( C )A、import java.sql.*;B、import java.util.*;C、import java.io.*;D、import java.net.*;
8.如果需要从文件中读取数据,则可以在程序中创建哪一个类的对象( A )A、FileInputStream B、FileOutputStream C、DataOutputStream D、FileWriter
9.下列描述错误的是( B )A、abstract类不可以用new运算符创建对象 B、允许使用final修饰abstract方法C、 abstract方法只允许声明,不允许实现 D、abstract类可以有abstract方法。
10.以下关于继承的叙述正确的是( A )。A、在Java中类只允许单一继承 B、在Java中一个类只能实现一个接口
得分第 2 页 共 6 页
C、在Java中一个类不能同时继承一个类和实现一个接口D、在Java中接口只允许单一继承
11. 在Java Applet程序用户自定义的Applet子类中,一般需要重载父类的( D )方法来完成一些画图操作。A、 start( ) B、 stop( )C、 init( ) D、 paint( )
12.在使用interface声明一个接口时,只可以使用( D )修饰符修饰该接口。A、private B、protected C、private protected D、public
13.下列叙述正确的是( B )A、重写父类方法时可以降低访问权限。B、 重写父类方法时不可以降低访问权限。C、final类可以被继承。 D、以上都不对。
14.下列关于构造方法的叙述中,错误的是( C )A、Java语言规定构造方法名与类名必须相同B、Java语言规定构造方法没有返回值,但不用void声明C、Java语言规定构造方法不可以重载D、Java语言规定构造方法只能通过new自动调用
15.下列描述错误的是( D )A、子类不继承父类的构造方法 B、可以在子类中使用Super关键字 C、 Super必须是子类的第一条语句 D、不可以使用Super操作被隐藏的成员方法。
二、填空题(每空2分,共30分)1.如果将类MyClass声明为public,它的文件名称必须是( MyClass.java )才能正常编译。
2.如果一个方法没有返回值,则该方法类型为( void )。3.线程创建后必须调用 start() 方法,新线程进入就绪队列排队。4.子类可以继承父类的( 非私有的 )成员。5.如果子类中的某个变量的变量名与它的父类中的某个变量完全一样,则称子类中的这个变量( 隐藏 )了父类的同名变量。
6.Java.net包中的 url 类是对统一资源定位符的抽象。7.异常处理是由( try )、( catch )和 finally 块三个关键所组成的程序块。
8. Jpanel 型容器的默认布局是FlowLayout型布局。9.选择框可以发生 ItemEvent 事件。
得分第 3 页 共 6 页
10.Socket通常也称为 ( 套接字 ),用于描述( IP地址 ) 和 ( 端口号 )。11.在类的声明中,通过使用关键字 extends 来声明一个类的子类。
12.Abstract类不能用 new 运算符创建对象。三、阅读下列程序段(共20分)1.a)类ChinaPeople拥有那些数据成员( x2,y1 ) (2分)b) 类ChinaPeople拥有那些方法( f2(), setHeight(),getHeight() )(2分)
c)画出对象p1的内存模型( )(4分)P1X1
X2Yclass People { private int x1; int x2; private f1(){} public int f2{}}class ChinaPeople extends People { int y1; public void setHeight(int h) { y1 = h; } public int getHeight() { return y1; }}public class Example { public static void main(String args[]) { ChinaPeople p1 = new ChinaPeople();
} }2.阅读程序,给出结果:
// AbstractClassDemo.java源代码如下:abstract class Shape { //定义抽象类Shape和抽象方法display
得分第 4 页 共 6 页
abstract void display();}class Circle extends Shape {void display() {//实现抽象类的方法System.out.println("Circle");}}class Rectangle extends Shape {void display() { //实现抽象类的方法System.out.println("Rectangle");}}class Triangle extends Shape {void display() { //实现抽象类的方法System.out.println("Triangle");}}public class AbstractClassDemo{public static void main(String args[]){(new Circle()).display();//定义无名对象来调用对应的display方法(new Rectangle()).display();(new Triangle()).display();}}输出结果是 Circle Rectangle Triangle
3.按注释提示完成文件复制的程序 //FileStream源代码如下: import java.io.*; class FileStream { public static void main(String args []) { try { File inFile = new File("file1.txt");//指定源文件 File outFile = new File("file2.txt");//指定目标文件 FileInputStream fis =( new FileInputStream(inFile) ); (3分)第 5 页 共 6 页
FileOutputStream fos = new FileOutputStream(outFile); int c; //逐字节从源文件中输入,再输出到fos流while ((c = fis.read ())!=-1) ( fos.write(c); ); (3分) fis.close(); fos.close();}catch (Exception e) { System.out.println("FileStreamsTest: "+e);} }}
四、 编程题(每题10分,共20分)1.按以下要求编写程序(1) 创建一个梯形Lader类,添加above,bottom,height和area成员变量。(2) 在Lader中添加方法给above,bottom,height赋值。(3) 在Lader中添加方法返回above,bottom,height的值。(4) 在Lader中添加构造方法给above,bottom,height赋初值。(5) 编程利用Lader输出一个梯形的面积
解答:public class Lader {float above,bottom,height,area;void setAbove(float x){this.above=x;}void setBottom(float x){this.bottom=x;}void setHeight(float x){this.heighr=x;}float getAbove(){return this.above;}float getBottom(){return this.bottom;}float getHeight(){return this.height;}Lader(float x,float y,float z){ this.above=x; this.bottom=y; this.height=z;}public float getArea(){return (this.above+this.bottom)*this.height/2.0;}public static void main(String [] args) {Lader p = new Lader(10, 20,30);System.out.println("面积是:" + p.getArea());
得分