[计算机类试卷]国家二级(JAVA)机试模拟试卷33及答案与解析.doc
《[计算机类试卷]国家二级(JAVA)机试模拟试卷33及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级(JAVA)机试模拟试卷33及答案与解析.doc(5页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级( JAVA)机试模拟试卷 33及答案与解析 一、基本操作题( 30分) 1 下面程序是关于类的继承的用法。阅读下面程序,根据程序中的注释在每一条横线处填写一个语句,使程序的功能完整,且运行程序后的输出结果为: I am parentclass! I am childclass! I am childclass! 注意 : 请勿改动 main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。 class Parent void printMe() System.out.println(“I am parentclass!“); class Child extends Pare
2、nt void printMe() System.out.println(“I am childclass!“); void printAll() _.printMe ( ); / 调用父类的方法 _. printMe ( ); /调用本类的方法 printMe ( ); public class TestJieCheng public static void main(String args) _ myC.printAll(); 二、简单应用题( 40分) 2 请完成下列 Java程序:读取新浪首页文件的数据并且显示出来。要求编写JFrame扩展类,以 String类的对象定义的 url地址
3、作为入口参数 ,该类实现根据 url参数指定的地址进行连接和读取数据,并且能显示在 1个文本区域内。 注意:请勿改动 main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。 程序运行结果如下: import javax.swing.*; import java.awt.*; import java.awt.event.*; import .*; import java.io.*; public class ex25_2 public static void main(String arg) UrlFrame page = new UrlFrame(“http:/“); page.s
4、how(); class UrlFrame extends JFrame JTextArea jta = new JmextArea(“正在读取文件 “); URL url; public UrlFrame(String strAddr) super (strAddr); / 使用父类的构造方法。 setSize(450, 300); JScrollPane jsp = new JScrollPane(jta); getContentPane().add(jsp); WindowListener wl = new WindowAdapter() public void windowClosin
5、g(WindowEvent we) System.exit(0); ; addWindowListener(wl); try url = new URL(strAddr); _; catch (MalformedURLException murle) System.out.println(“不合适的 URL: “+ strAddr); void getData(URL url) URLConnection con = null; InputStreamReader isr; BufferedReader readBuf; String strLine; StringBuffer strBuf
6、= new StringBuffer(); try con = this.url.openConnection(); con.connect(); jta.setText(“打开连接 .“); isr = new InputStreamReader(con.getInputStream( ); readBuf = new BufferedReader(isr); jta.setText(“读取数据 .“); while (strLine = readBuf.readLine() != null) strBuf.append(strLine + “n“); _; catch (IOExcepti
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 JAVA 模拟 33 答案 解析 DOC
