面向对象程序设计JAVA语言程序设计》期末考试试题及部分答案.doc

上传人:11****ws 文档编号:2253305 上传时间:2019-05-03 格式:DOC 页数:7 大小:36KB
下载 相关 举报
面向对象程序设计JAVA语言程序设计》期末考试试题及部分答案.doc_第1页
第1页 / 共7页
面向对象程序设计JAVA语言程序设计》期末考试试题及部分答案.doc_第2页
第2页 / 共7页
面向对象程序设计JAVA语言程序设计》期末考试试题及部分答案.doc_第3页
第3页 / 共7页
面向对象程序设计JAVA语言程序设计》期末考试试题及部分答案.doc_第4页
第4页 / 共7页
面向对象程序设计JAVA语言程序设计》期末考试试题及部分答案.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

1、面向对象程序设计 JAVA 语言程序设计期末考试试题及部分答案 2 一、单选择题(每小题 2 分,共 10 分)1、编译 Java Application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为( B )。A. .java B. .classC. .html D. .exe2、设 x = 1 , y = 2 , z = 3,则表达式 yz/x 的值是( A )。A. 3 B. 3. 5C. 4 D. 53、在 Java Applet 程序用户自定义的 Applet 子类中,一般需要重载父类的 ( D )方法来完成一些画图操作。A. start( ) B. stop( )C.

2、 init( ) D. paint( )4、不允许作为类及类成员的访问控制符的是( C )。A. public B. privateC. static D. protected5、为 AB 类的一个无形式参数无返回值的方法 method 书写方法头,使得使用类名 AB 作为前缀就可以调用它,该方法头的形式为( A )。A. static void method( ) B. public void method( ) C. final void method( ) D. abstract void method( )二、填空题(每空格 1 分,共 20 分)1、开发与运行 Java 程序需要经过

3、的三个主要步骤为 编辑源程序 、编译生成字节码、 和 解释运行字节码 。2、如果一个 Java Applet 源程序文件只定义有一个类,该类的类名为 MyApplet,则类MyApplet 必须是 Applet、 类的子类并且存储该源程序文件的文件名为 MyApplet 。3、如果一个 Java Applet 程序文件中定义有 3 个类,则使用 Sun 公司的 JDK 编译器 javac.exe 编译该源程序文件将产生 3 个文件名与类名相同而扩展名为 .class 的字节码文件。4、在 Java 的基本数据类型中,char 型采用 Unicode 编码方案,每个 Unicode 码占用 2

4、字节内存空间,这样,无论是中文字符还是英文字符,都是占用 2 字节内存空间。5、设 x = 2 ,则表达式 ( x + + )3 的值是 0 。6、若 x = 5,y = 10,则 x = y 的逻辑值分别为 true 和 false 。7、 抽象(abstract)方法 方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法必须在抽象类之中定义。 最终(final)方法 方法是不能被当前类的子类重新定义的方法。8、创建一个名为 MyPackage 的包的语句是 package MyPackage ; ,该语句应该放在程序的位置为: 应该在程序第一句 。9、设有数组定义:int MyIn

5、tArray = 10 , 20 , 30 , 40 , 50 , 60 , 70; 则执行以下几个语句后的输出结果是 120 。int s = 0 ;for ( int i = 0 ; i = 0 ; i )System.out.print(ai+“ “);System.out.println( );3、 import java.awt.*;public class abc public static void main(String args) new FrameOut(); class FrameOut extends Frame / Frame 为系统定 Button btn; / 义

6、的窗框类FrameOut( ) super(“按钮“);btn = new Button(“按下我“);setLayout(new FlowLayout( );add(btn);setSize(300,200);show( );4、import java.io.*;public class abc public static void main(String args) SubClass sb = new SubClass( ); System.out.println(sb.max( );class SuperClass int a = 10 , b = 20 ; class SubClass

7、 extends SuperClass int max( ) return (ab)?a:b); 四、写出下面程序的运行结果(每小题 10 分,共 30 分)1、 import java.io.*;public class abc public static void main(String args ) AB s = new AB(“Hello!“,“I love JAVA.“);System.out.println(s.toString( );class AB String s1;String s2;AB( String str1 , String str2 ) s1 = str1; s2

8、 = str2; public String toString( ) return s1+s2;2、 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 max ) max=temp;if (temp min) min=temp; catch ( IOException e ) ;System.out.println(“max=“+max+

9、“nmin=“+min); 2、参考程序如下:import java.applet.* ; import java.awt.* ;public class abc extends Applet Complex a,b,c ;public void init( ) a = new Complex(1,2); b = new Complex(3,4); c = new Complex(); public void paint(Graphics g) c=plexAdd(b);g.drawString(“第一个复数: “+a.toString(),10,50);g.drawString(“第二个复数

10、: “+b.toString(),10,70);g.drawString(“两复数之和: “+c.toString(),10,90);class Complexint RealPart ; / 复数的实部 int ImaginPart ; / 复数的虚部Complex() RealPart = 0 ; ImaginPart = 0 ; Complex(int r , int i) RealPart = r ; ImaginPart = i ; Complex complexAdd(Complex a)Complex temp = new Complex( ); / 临时复数对象temp.RealPart=RealPart+a.RealPart;temp.ImaginPart=ImaginPart+a.ImaginPart;return temp;public String toString( ) return ( RealPart+“ + “+ImaginPart+“ i “); (完)

展开阅读全文
相关资源
相关搜索
资源标签

当前位置:首页 > 实用文档资料库 > 策划方案

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。