浙江工商大学Java期末试卷(A,2009-2010).doc_第1页
浙江工商大学Java期末试卷(A,2009-2010).doc_第2页
浙江工商大学Java期末试卷(A,2009-2010).doc_第3页
浙江工商大学Java期末试卷(A,2009-2010).doc_第4页
浙江工商大学Java期末试卷(A,2009-2010).doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

2009 /2010 一. 单项选择题(共10题,每题3分)1在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数个数、类型或顺序各不相同,传回的值也可以不相同。这种面向对象程序的特性称为( C )。A、隐藏 B、覆盖 C、重载 D、继承2.以下关于构造函数的描述错误的是( A )。A、构造函数的返回类型只能是void型。B、构造函数是类的一种特殊函数,它的方法名必须与类名相同。C、构造函数的主要作用是完成对类的对象的初始化工作。D、一般在创建新对象时,系统会自动调用构造函数。3.设有下面两个类的定义: public class Person String name; /姓名 long id; /身份证号 class Student extends Person int score; / 入学总分 int getScore() return score; 则类Person和类Student的关系是( B )。A、包含关系B、继承关系C、关联关系D、上述类定义有语法错误4. 下列哪一种main()方法的声明是合法的? ( B )A. public static void main() B. public static void main(String args) C. void main(String args) D. public void static main(String args) 5.若类A的成员的访问控制符为默认(即未定义),关于该成员访问控制权限的正确描述是( )。 A、只能被A的成员方法访问。B、只能被与A在同一个包里的类的成员方法访问。 C、只能被A的子类的成员方法访问。D、可以被所有类访问。6.有以下方法的定义,请选择该方法的返回类型是什么?( D )。ReturnType method(byte x, double y)return (short)x/y*2;A、byteB、shortC、intD、double7为了以字节方式从文件读出内容,可以使用哪个类?( )A、FileReaderB、FileInputStreamC、FileOutputSteamD、FileWriter8. 设有类型定义short i=32;long j=64;下面赋值语句中哪一个是不正确的?( )A. j=i B. i=j C. i=(short)j D. j=(long)i9. 在某个类A中存在一个方法:void GetSort(int x),以下哪一项能作为这个方法的重载的声明?( )A. void GetSort(float x) B. int GetSort(int y)C. double GetSort(int x,int y) D. void Get(int x,int y)10. 为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用AB.method()就可以调用该方法,该方法的形式为下面哪一种?( )A. public void method()B. static void method()C. final void method()D. abstract void method()二. 程序阅读题(共8题,每题5分)11 写出以下程序段的输出结果。import java.io.*;public class abcpublic static void main(String args ) int i,s = 0; int a = 10,20,30,40,50,60,70,80,90; for(i = 0; i 0) return x+ + +y+i; else return x+ - +(-y)+i; public static void main(String args) Complex c1=new Complex(2,1.5); Complex c2=new Complex(-0.8,-3); c1.plus(c2); System.out.println(c1.toString(); 回答:1.2 - 1.5i17写出以下程序段的输出结果: import java.io.*;public class Testpublic static void main(String args)trythrow new IOException();catch(IOException npex)System.out.println(IOException thrown);catch(ArrayIndexOutOfBoundsException ex)System.out.println(ArrayIndexOutOfBoundsException thrown);finallySystem.out.println(Done with exceptions );System.out.println(myMethod is done);回答:IOException thrownDone with exceptionmyMethod is done18下面HTML代码用于显示,写出程序的运行结果:import java.applet.*;import java.awt.*;public class AppletTest extends Applet int localnum,paranum;public void init()localnum+;paranum=Integer.parseInt(getParameter(age);public void paint(Graphics g)paranum+;String a=localnum=+localnum;g.drawString(a,5,50);g.drawString(paranum=+paranum,5,80); 回答:三. 程序设计题(30分)19(5分)下列程序的功能是:从命令行接受用户输入的10个整数,并输出这10个整数中的最大值和最小值。请在下面横线处填入正确的代码,使程序可以正确运行。import java.io.* ;public class exam44 public static void main(String args ) int i, n = 10, max = 0 , min = 0 , temp = 0; try BufferedReader br = new BufferedReader( new InputStreamReader(System.in); max = min = Integer.parseInt( ); catch ( IOException e ) ; for ( ) try BufferedReader br = new BufferedReader( new InputStreamReader(System.in); temp = Integer.parseInt( ); if (temp max ) ; if (temp rec.getLength()* this.getWidth() return 1; else return -1;double length;double width;public Rectangle() / 此构造方法无参数,缺省的给出长(20)和宽(10)this.length = 20;this.width = 10;public Rectangle(double length, double width) / 此构造方法给出长和宽this.length = length;this.width = width;public Rectangle(Rectangle rect) / 此构造方法以另一个Rectangle为参数this.length = rect.length;this.width = rect.width;public double getLength() return length;public double getWidth() return width;public static void main(String args) Rectangle rect1 = new Rectangle ( ); Rectangle rect2 = new Rectangle (50,40);Rectangle rect3 = new Rectangle (rect2);_System.out.println(rect3.length=+(int)rect3.getLength()+rnrect3.width=+(int)rect3.width)_;int d=_pareTo(rect1)_;if(d=1) System.out.println(“The Area of rect3 is larger than rect1”);if(d=-1) System.out.println(“The Area of rect3 is little than rect1”);if(d=0) System.out.println(“The Area of rect3 is equal to rect1”);请在上面空白处和横线处填入适当代码,使程序可以运行输出为:rect3.length=50rect3.width=40The Area of rect3 is larger than rect121(12分)用Java编写AWT用户界面处理程序,在一个Frame窗口中放置一个button按钮和一个文本域控件,Frame窗口应当是可以关闭的。当用户单击button按钮时,程序将按钮上的文字添加到文本域中。import java.awt.Frame;import java.awt.GridLayout;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import javax.swing.JButton;import javax.swing.JTextArea;public class Test extends Frame implements MouseListener, WindowListenerprivate JButton btn = new JButton(Button 1);private JTextArea text = new JTextArea();public Test()super.setBounds(300, 300, 50, 50);super.setLayout(new GridLayout(2, 1);super.add(btn);super.add(text);btn.addMouseListener(this);super.addWindowListener(this);super.setVisible(true);super.pack();public void mouseClicked(MouseEvent e) text.setText(text.getText().concat(btn.getText();super.pack();public void mouseEntered(MouseEvent e) public void mouseExited(MouseEvent e) public void mousePressed(MouseEvent e) public void mouseReleased(MouseEvent e) public static void main(String args) new Test();public void windowActivated(WindowEvent e) publi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论