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

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

《面向对象程序设计java语言程序设计》期末考试试题及部分答案》由会员分享,可在线阅读,更多相关《面向对象程序设计java语言程序设计》期末考试试题及部分答案(7页珍藏版)》请在金锄头文库上搜索。

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

2、画图操作。A. start( ) B. stop( )C. init( ) D. paint( ) 4、不允许作为类及类成员的访问控制符的是( C )。A. public B. privateC. static D. protected 5、为 AB 类的一个无形式参数无返回值的方法 method 书写方法头,使得使用类名 AB 作 为前缀就可以调用它,该方法头的形式为( A )。A. static void method( ) B. public void method( ) C. final void method( ) D. abstract void method( )二、填空题(每空

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

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

5、 ; , 该语句应该放在程序的位置为: 应该在程序第一句 。 9、设有数组定义:int MyIntArray = 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 Fr

6、ameOut extends Frame / Frame 为系统定 Button btn; / 义的窗框类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( );clas

7、s SuperClass int a = 10 , b = 20 ; class SubClass 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; St

8、ring s2; AB( String str1 , String str2 ) s1 = str1; s2 = 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;

9、catch ( IOException e ) ;System.out.println(“max=“+max+“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.dra

10、wString(“第一个复数:“+a.toString(),10,50);g.drawString(“第二个复数:“+b.toString(),10,70);g.drawString(“两复数之和:“+c.toString(),10,90); class Complex int 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 “); (完)

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号