网络学院Java复习题+答案_第1页
网络学院Java复习题+答案_第2页
网络学院Java复习题+答案_第3页
网络学院Java复习题+答案_第4页
网络学院Java复习题+答案_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

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

文档简介

1、Java语言程序设计复习题二一、判断题(每小题1分,共5分)1、( )子类要调用父类的方法,必须使用super关键字。2、( )有的类定义时可以不定义构造函数,所以构造函数不是必需的。3、( )如果p是父类Parent的对象,而c是子类Child的对象,则语句c = p是正确的。4、( )在Java语言中,系统常量null,false,true既可以大写,也可以小写。5、( )Java语言没有无符号整数类型、指针类型、结构类型、枚举类型、共用体类型。二、单项选择题(每小题1分,共35分)1、计算机中的流是 流动的字节 流动的对象 流动的文件 流动的数据缓冲区2、一个Java Applicati

2、on运行后,在系统中是作为一个 线程 进程 进程或线程 不可预知3、实现下列 接口可以对TextField对象的事件进行监听和处理。ActionListener FocusListener MouseMotionListener WindowListener4、Frame的默认布局管理器是 FlowLayoutBorderLayoutGridLayoutCardLayout5、每个使用Swing构件的程序必须有一个 按钮 标签 菜单 容器6、Applet运行时,被浏览器或appletviewer调用的第一个方法是 paint() init() start() destroy()7、Applet

3、类的直接父类是 Component类Container类Frame类Panel类8、在Applet生命周期中,下列 方法是在装载Applet时被调用。stop() init() start() destroy()9、在一个applet标记中, 标记属性项可以省去不写。code codebase width height10、下列命令中, 命令是Java的编译命令。javac java javadoc appletviewer11、下列语句的输出结果是 。true false 1 012、下列各输出语句中,显示结果为“123”的是 1+2+3);1+""+2+3);1+2+3

4、+"");1+2+""+3);13、若在某一个类定义中定义有方法:abstract void f();则该类是 public类 final类 抽象类 不能确定14、main方法是Java Application程序执行的入口点,下列 main方法原型是不正确的。public static void main(Stringargs)public static void main(String args)public static void main(Stringa)public static void main(stringargs)15、在Java中,用

5、 关键字定义常量。#define fixed const final16、在Java语言中, 包是自动导入的。java.lang java.awt java.applet java.io17、如果一个Java源程序文件中定义有4个类,则使用Sun公司的SDK编译器javac.exe编译该源程序文件,将产生 个文件名与类名相同而扩展名为.class的字节码文件。1 2 3 418、下列 不是Java的保留字。do double sizeof while19、在Java中, 语句作为异常处理的统一出口。throw try finally catch20、下列语句输出结果为 。0xa a 1 102

6、1、下列常见的系统定义的异常中, 是输入、输出异常。ClassNotFoundException IOExceptionFileNotFoundException UnknownHostException22、下列叙述错误的是 Java是一种面向对象的网络编程语言Java Applet程序在网络上传输不受硬软件平台的限制Java提供了类库支持TCP/IP协议Java语言允许使用指针访问内存23、下列代码的执行结果是 。public class A public static void main(Stringargs)"ababcc" "464688" &

7、quot;46abc8" "10abc8"24、下列叙述中不正确的是 abstract不能与final并列修饰同一个类abstract类中不可以有private的成员abstract方法必须在abstract类中static方法中能直接处理非static的属性25、在Applet的关键方法中,下列 方法是关闭浏览器以释放Applet占用的所有资源。init() start() stop() destroy()26、下列Java常见事件类中 是鼠标事件类。InputEvent KeyEvent MouseEvent WindowEvent27、下列类定义中不正确的是

8、 public class A extends Bpublic class A extends B,Dpublic class A implements B,Dpublic class A extends B implements C,D,E28、如果子类中覆盖了父类中的同名方法,则在子类中调用父类中的同名方法时应使用关键字 this super implements extends29、在Java中,子类重新定义一个与从父类那里继承来的域变量(成员变量)完全相同的变量,这称为域的 隐藏 覆盖 重载 Java不支持此特性30、为了区分同一个类中重载的各个同名方法,要求 采用不同的形式参数列表(

9、形式参数的个数、类型、顺序不完全相同)返回值的数据类型不同调用时用类名或对象名做前缀 形式参数名不同31、Give the following java source fragement:/point xpublic class Interesting/do somethingWhich statement is correctly Java syntax at point x? package mypackagestatic int PI=3.14 public class MyClass/do other thing32、A class design requires that a mem

10、ber variable should be accessible only by same package, which modifer word should be used? protected public no modifer private33、Which modifer should be applied to a declaration of a class member variable for the value of variable to remain constant after the creation of the object? static final con

11、st abstract34、What happens when you try to compile and run the following program? class MysteryString s; public static void main(String args) Mystery m=new Mystery();m.go(); void Mystery()s="constructor" this code will not compilethis code compliles but throws an exception at runtimethis c

12、ode runs and "constructor" in the standard outputthis code runs and writes "null" in the standard output35、Give the following java class:public class Examplepublic static void main(String args) Which statement is corrected? When compile, some error will occur.When run, some error

13、 will occur.Output is zero. Output is null.三、程序改错题(每小题2分,共10分)1、class parent private int mine;class child extends parentint getMine()return mine; 2、class parentprivate int mine; int getMine()return mine; class child extends parent int mine; int getMine() return super.getMine; 3、class AmIWrongint dat

14、a1,data2; AmIWrong()data1=-1; AmIWrong(int d) data2=d;this(); 4、interface MyInterfacevoid method1();abstract class Parent implements MyInterfaceclass Child extends Parent void method1()"I am implemented now!"); 5、import public class Apublic static void main(Stringargs) JFrame f=new JFrame(

15、"Swing Application"); JLabel t=new JLabel("Goodbye!"); f.add(t); f.setSize(100,100); f.setVisible(true); 四、程序分析填空题(每小题5分,共10分)1、在本程序中,主窗口有一个“文件”菜单,“文件”菜单有一个菜单项“退出”,该菜单项还有一个快捷键“Ctrl+E”,点击“退出”菜单项或使用快捷键“Ctrl+E”都可能退出程序。如图所示。class A extends Frame implements ActionListenerMenuBar mb;Me

16、nu m;MenuItem mi;MenuShortcut sc=new MenuShortcut(KeyEvent.VK_E);A(String s)super(s);setSize(160,170);setVisible(true);mb=new MenuBar();m=new Menu("文件");mi=new MenuItem("退出"); mi.addActionListener(this);m.add(mi);mb.add(m); public void actionPerformed(ActionEvent e)if(e.getSource

17、()=mi)System.exit(0);public class Bpublic static void main(Stringargs)A a=new A("GUI");2、本程序在页面上有两个按钮“Dialog”和“Exit”,当单击“Dialog” 按钮时将弹出一个对话框,单击“Exit” 按钮时将关闭窗口,如图所示。public class D extends WindowAdapter implements ActionListenerFrame f=new Frame("GUI");Button b1=new Button("Di

18、alog");Button b2=new Button("Exit");Dialog d=new Dialog(f,"Dialog",true);public D() f.add(b1,"West"); f.add(b2,"Center"); b1.addActionListener(this); d.add("Center",new Label("I'm a Dialog"); d.setSize(100,100); d.addWindowListener

19、(this); f.addWindowListener(this); f.setSize(200,200); f.setVisible(true); public static void main(String args)new D();public void actionPerformed(ActionEvent e)String s=e.getActionCommand(); if(s.equals("Dialog")d.setVisible(true); else if(s.equals("Exit")System.exit(1);public v

20、oid windowClosing(WindowEvent e)System.exit(1);五、读程序,写出其运行结果(每小题5分,共20分)1、class sub1public int x,y;sub1(int a,int b)x=a;y=b;class sub2 extends sub1sub2(int a,int b)super(a,b);class A extends sub2A(int x,int y)super(x,y);public static void main(Stringargs)sub1 k1=new sub1(10,15);sub2 k2=new sub2(10,1

21、5);A k3=new A(10,15);k1.display();k2.display();k3.display();2、class S implements Runnable");public void run()for(int i=0;i<3;i+) public class A extends Thread");public void run()for(int i=0;i<3;i+) public static void main(Stringargs)new Thread(new S().start();new A().start();3、class

22、MyException extends Exceptionpublic class Apublic void f() throws MyException throw new MyException();public static void main(Stringargs)A a=new A();trya.f();4、public void init()Label s=new Label("-申请邮箱界面-");Font.PLAIN,20);s.setForeground(Color.blue);add(s);add(new Label("用 户ID:"

23、);add(new TextField(15);add(new Label("用户密码:");add(new TextField(15);add(new Label("密码确认:");add(new TextField(15);add(new Label("性别:");CheckboxGroup a=new CheckboxGroup();add(new Checkbox("男",a,false);add(new Checkbox("女",a,true);add(new Label("

24、地区");Choice b=new Choice();b.addItem("广东");b.addItem("上海");b.addItem("北京");b.addItem("");add(b);add(new Label("邮箱类别:");List c=new List(3,false);c.add("收费邮箱");c.add("免费邮箱");c.add("VIP邮箱");add(c);add(new Button("

25、提交");add(new Button("取消");六、编程题(每小题10分,共20分)1、创建一个窗口,窗口中有“退出”按钮,“文件”菜单下有“打开”、“关闭”和“退出”菜单项,“关闭”和“退出”菜单项之间有分隔条。要求分别单击“退出”菜单项、“退出”按钮和窗口本身的关闭按钮时都能关闭本窗口。如图所示。2、编写一个程序,窗口上有两个按钮:“New”和“Close all”。每点击一次“New”按钮,就会生成一个新的对话框,且新对话框窗口的标题是“Window X”(X为生成的窗口的个数),点击“Close all”按钮后将关闭所有新生成的对话框。如图所示。Jav

26、a语言程序设计复习题二参考答案一、判断题(每小题1分,共5分)1、× 2、 3、× 4、× 5、二、单项选择题(每小题1分,共35分)1、2、3、4、5、6、7、8、9、10、11、12、13、14、15、16、17、18、19、20、21、22、23、24、25、26、27、28、29、30、31、32、33、34、35、三、程序改错题(每小题2分,共10分)1、子类成员方法不能直接访问父类的私有成员,应将去掉private2、应将return super.getMine;改为return super.getMine();3、应将AmIWrong(int d)d

27、ata2=d;this();改为AmIWrong(int d)this();data2=d;4、应将void method1()改为public void method1()5、应将f.add(t);改为f.getContentPane().add(t);四、程序分析填空题(每小题5分,共10分)1、mi.setShortcut(sc);setMenuBar(mb);2、b2.addActionListener(this);五、读程序,写出其运行结果(每小题5分,共20分)1、z=25z=150z=1502、3、Throwing MyException from f()Caught it!4、

28、六、编程题(每小题10分,共20分)1、import jpublic class A extends Frame implements ActionListenerMenuBar mb=new MenuBar();Menu m1= new Menu("文件");MenuItem open=new MenuItem("打开");MenuItem close=new MenuItem("关闭");MenuItem exit=new MenuItem("退出");Button b=new Button("退出&

29、quot;);Panel p=new Panel();A()super("MyGUI"); setSize(350,200); m1.add(open); m1.add(close); m1.addSeparator(); m1.add(exit); add("South",p);p.add(b);b.addActionListener(this);exit.addActionListener(this);mb.add(m1);setMenuBar(mb);show();public static void main( String args)A f=new A();f.addWindowListener(new WindowAdapter() public void windowC

温馨提示

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

评论

0/150

提交评论