




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
贵州大学实验报告学院:计算机科学与信息学院 专业:网络工程 班级:091姓名邱东生学号0908060327实验组实验时间0420指导教师曹琳成绩实验项目名称实验三 基本实验三、接口的使用实验目的1、学会JAVA小程序的设计,并在JCREATOR上运行,发现小问题。2、学会通过接口实现多态。实验要求根据老师给的程序,在JCREATOR上运行并分析。实验原理正确处理JAVA实验程序,并进行分解。JAVA中可用接口来实现多态。实验仪器JCREATOR实验步骤1、 按题目顺序对程序进行运行。2、 根据题目要求编程。3、 对结果进行分析,若错误分析原因。4、 运行书中例5-5得实验结果并进行分析。实验内容一、1、Give the following code: public class Example public static void main(String args ) int l=0; do System.out.println(“Doing it for l is:”+l); while(-l0) System.out.println(“Finish”); Which well be output: A. Doing it for l is 3 B. Doing it for l is 1 C. Doing it for l is 2 D. Doing it for l is 0 0E. Doing it for l is ?C1 F. Finish2、 Give incompleted method: 1) 2) if(unsafe()/do something 3 else if(safe()/do the other 4 The method unsafe() well throw an IOException, which completes the method of declaration when added at line one? A. public IOException methodName() B. public void methodName() C. public void methodName() throw IOException D. public void methodName() throws IOException 0E. public void methodName() throws Exception 3、 Give the following method: public void example() try unsafe(); System.out.println(“Test1”); catch(SafeException e)System.out.println(“Test 2”); finallySystem.out.println(“Test 3”); System.out.println(“Test 4”); Which will display if method unsafe () run normally? A. Test 1 0B. Test 2 C. Test 3 0D. Test 4 04、 The following code is entire contents of a file called Example.java,causes precisely one error during compilation: 1) class SubClass extends BaseClass 2 3) class BaseClass() 4 String str; 5 public BaseClass() 6 System.out.println(“ok”); 7 public BaseClass(String s) 8 str=s; 9) public class Example 10 public void method() 11 SubClass s=new SubClass(“hello”); 12 BaseClass b=new BaseClass(“world”); 13 14 Which line would be cause the error? A. 9 B. 10 C. 11 0 D.12 5、 Give the following java source fragement: /point x public class Interesting /do something Which statement is correctly Java syntax at point x? A. import java.awt.*; 0B.package mypackage C. static int PI=3.14 D. public class MyClass/do other thing E. class MyClass/do something6、 Give the following class defination inseparate source files: public class Example public Example()/do something protected Example(int i)/do something protected void method()/do something public class Hello extends Example/member method and member variable Which methods are corrected added to the class Hello? A. public void Example() B. public void method() 0C. protected void method() 0D. private void method() 7、 Give following class: class AClass private long val; public AClass(long v)val=v; public static void main(String args) AClass x=new AClass(10L); AClass y=new AClass(10L); AClass z=y; long a=10L; int b=10; Which expression result is true? A. a=b; B. a=x; C. y=z; 0D. x=y; E. a=10.0; 8、 What happens when you try to compile and run the following program? class Mystery String s; public static void main(String args) Mystery m=new Mystery(); m.go(); void Mystery() s=”constructor”; void go() System.out.println(s); A. this code will not compile B. this code compliles but throws an exception at runtime C. this code runs but nothing appears in the standard output D. this code runs and “constructor” in the standard output E. this code runs and writes ”null” in the standard output 09、 Select valid identifier of Java: A. userName 0B. %passwd C. 3d_game D. $charge E. this10、 Give the following java class: public class Example static int x=new int15; public static void main(String args) System.out.println(x5); Which statement is corrected? A. When compile, some error will occur. B. When run, some error will occur. C. Output is zero. 0D. Output is null. 11、 Give the following class: public class Example String str=new String(“good”); char ch=a,b,c;public static void main(String args) Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.println(ex.str+”and”+ex.ch); public void change(String str,char ch) str=”test ok”;ch0=g; Which is the output: A. good and abc B. good and gbc 0C. test ok and abc D. test ok and gbc 12、 Give following fragment. Outer: for(int i=0; i3; i+) inner:for(int j=0;j1)break outer; System.out.println(j+”and”+i); Which will be output? A. 0 and 0 0 B. 0 and 1 C. 0 and 2 D. 0 and 3 E. 1 and 0 0 F. 1 and 1 G. 1 and 2 H. 1 and 3 I. 2 and 0 J. 2 and 1 K. 2 and 2 L. 2 and 3 二、例5-5import java.util.*;/将Shape定义为interfaceinterface Shape void draw(); void erase();/定义Circle类实现Shapeclass Circle implements Shape public void draw() System.out.println(Calling Circle.draw(); public void erase() System.out.println(Calling Circle.erase(); /定义Square类实现Shapeclass Square implements Shape public void draw() System.out.println(Calling Square.draw(); public void erase() System.out.println(Calling Square.erase(); /定义Triangle类实现Shapeclass Triangle implements Shape public void draw() System.out.println(Calling Triangle.draw(); public void erase() System.out.println(Calling Triangle.erase(); /包含main()的测试类public class NewShapes static void drawOneShape(Shape s) s.draw(); static void drawShapes(Shape ss) for(int i = 0; i ss.length; i+) ssi.draw(); public static void main(String args) Random rand = new Random(); Shape s = new Shape9; for(int i = 0; i s.length; i+) switch(rand.nextInt(3) case 0: si = new Circle();break; case 1: si = new Square();break; case 2: si = new Triangle();break; drawShapes(s); 实验数据实验结果:一、1、2、D3、4、D5、A 6、BC 7、C8、9、A10、11、12、二、分析:将
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年宠物美容AI技术面试题库
- 2025年安全战略填空题库
- 2025年导盲犬训练高级面试实战题库
- 2025年广播电视台后期制作面试常见问题解答
- 2025年语音合成师职业发展面试题及答案
- 2025年高效学习方法与技巧高级笔试预测题
- 2025年地震救援面试重点题解析及答案
- 2025年建筑装饰设计师专业技术考核试卷及答案解析
- 课件中控件的使用
- 2025年环保工程技术师资格考试试题及答案解析
- 2025年中级会计职称考试经济法冲刺试题及答案
- 乐器供销合同范本
- 2025年辽宁省中考生物学试卷真题附答案
- 2025-2030牛肉分销渠道冲突与供应链协同优化报告
- 《法律职业伦理(第3版)》全套教学课件
- 2025年青岛市崂山旅游集团招聘考试笔试试题
- 2025年秋季新学期全体中层干部会议校长讲话:在挑战中谋突破于坚实处启新篇
- 2025年幼儿园保育员考试试题(附答案)
- 2025年上半年中国铁路兰州局集团有限公司校招笔试题带答案
- 《物联网导论》课程标准
- 供水抄表员安全知识培训课件
评论
0/150
提交评论