Java面向对象程序设计试题二答案.doc_第1页
Java面向对象程序设计试题二答案.doc_第2页
Java面向对象程序设计试题二答案.doc_第3页
Java面向对象程序设计试题二答案.doc_第4页
Java面向对象程序设计试题二答案.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

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

文档简介

Java面向对象程序设计试题二答案一、 选择题答案 选择第1题:D选择第2题:D选择第3题:C选择第4题:D选择第5题:D选择第6题:C选择第7题:B选择第8题:D选择第9题:C选择第10题:A二、多项选择题答案 多项选择第1题:ACD多项选择第2题:AB多项选择第3题:AD多项选择第4题:CD多项选择第5题:AD多项选择第6题:AC多项选择第7题:AD多项选择第8题:BC多项选择第9题:BD多项选择第10题:BCD三、 填空题答案 填空第1题:Collection,List,Map,Set填空第2题:Object填空第3题:java.lang.Character;java.lang.Boolean填空第4题:7填空第5题:因为在A的main方法中,还没有A的实例就要试图生成内部类的实例 四、 编程题答案编程第1题import java.io.*;public class Pointint x,y;public Point(int x,int y)this.x = x;this.y = y;public Point getPoint()Point tempPoint = new Point(x,y);return tempPoint;public void setPoint(Point point)this.x = point.x;this.y = point.y;public static void main(String args)Point Point1 = new Point(3,4);System.out.println(Point1:+(+Point1.x+,+Point1.y+);Point Point2 = Point1.getPoint();System.out.println(Point2:+(+Point2.x+,+Point2.y+);Point Point3 = new Point(5,6);Point1.setPoint(Point3);System.out.println(Point1:+(+Point1.x+,+Point1.y+); 编程第2题import java.io.*;class FileCopypublic static void main(String args)FileInputStream in;FileOutputStream out;if (args.length2)System.out.println(Usage: java copy srcfile destfile);System.exit(-1); try in = new FileInputStream(args0);out = new FileOutputStream(args1);copyFile(in,out);catch (Exception e)System.out.println(e);private static void copyFile(FileInputStream in, FileOutputStream out)int length;byte buf = new byte1024;trywhile (length=in.read(buf,0,1024)!=-1)out.write(buf, 0, length); catch (Exception e)System.out.println(Error:+e);System.exit(-1);编程第3题import java.io.*; public class SelectSortpublic static void main(String args)int a=20,10,50,40,30,70,60,80,90,100;int temp;for (int i=0; ia.length-1;i+)for (int j=i+1; ja.length ; j+)if (aiaj) temp=ai;ai=aj; aj=temp; for (int k=0;ka.length ;k+)System.out.println(a+k+:+ak);编程第4题import java.io.*;import .*; public class HelloServerpublic static void main(String args) throws IOExceptionServerSocket server=null;server = new ServerSocket(8888);Socket ClientSocket = null;ClientSocket = server.accept();String line;BufferedReader is = new BufferedReader(new InputStreamReader(ClientSocket.getInputStream();PrintWriter os = new PrintWriter(ClientSocket.getOutputStream();while (true)line = is.readLine();if (line.equals(hello) os.println(hello);os.flush(); 编程第5题import java.awt.*;import java.awt.event.*;import java.applet.*;import java.util.*;public class TimeViewer extends Applet implements ActionListener, Runnable Thread timer;TextField in, out;Button bb;Panel p1, p2, p3;boolean state;public void init() in = new TextField(20); out = new TextField(20);bb = new Button(Current Time:);p1 = new Panel();p2 = new Panel();p3 = new Panel();setLayout(new GridLayout(3, 1);setSize(200,100);p1.add(in);p2.add(bb);p3.add(out);add(p1);add(p2);add(p3);bb.addActionListener(this); timer = new Thread(this);state = true;timer.start(); public void actionPerformed(ActionEvent e) /out.setText(in.getText();out.setText(currentTime(); public void run() while(true) try timer.sleep(1000); catch (InterruptedException

温馨提示

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

评论

0/150

提交评论