java复习指南2.doc_第1页
java复习指南2.doc_第2页
java复习指南2.doc_第3页
java复习指南2.doc_第4页
java复习指南2.doc_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

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

文档简介

复习指南:考试题型:1、选择题,30题 共45分3、读程序 4题 共20分4、简答题 2题 10分3、编程题 25分 (2题)复习重点:前13章 和22章选择题:出题思路:围绕吴老师理论课所讲内容出题,以基本概念、基本语法以及类库知识等等:这一部分大家要多看书,跟我之前考PASCAL有点像。 简答题复习重点:1、 什么是多态,java中如何实现多态?多态,也称为动态绑定,指在执行期间(而非编译期间)判断所引用对象的实际类型,根据其实际的类型调用其相应的方法。 子类重写父类的方法,并把子类对象的引用赋值给父类,当你调用父类里面被覆盖方法的时候, 实际当中new的是哪个对象, 就调用当前这个对象(子类对象)的与之相关的覆盖方法。2、 什么叫容器布局,布局都有哪些?布局是指:将组件按一定的顺序和规则放在窗体上的方式。有BorderLayout、FlowLayout、GridLayout、GridBagLayout、BoxLayout、绝对定位。3、 Java中有一种小应用程序片,Applet,简述如何工作的 Applet是一种可以在Internet上传递,并在Web浏览器中运行的程序(出于安全性,只能在所谓的沙盒中运行)。含有Applet的网页的HTML文件代码中部带有 和这样一对标记,当支持Java的网络浏览器遇到这对标记时,就将下载相应的小应用程序代码并在本地计算机上执行该Applet。 具体步骤:用Java语言编写一个Applet源程序; 把Applet源程序编译成字节码; 将Applet字节码嵌入Web页,即设计一个包含Applet的HTML文件; 用带有Java解释功能的浏览器浏览嵌有Applet的Web页。此时,浏览器会根据 HTML文件的有关标记下载相应的Applet,然后,由浏览器的字节码解释器边解释边执行。4、 迭代器的作用及其优势作用:用来抓取容器中的元素,并将抓取到的元素提交给迭代器用户。不用重写代码就可以应用于不同类型的容器。优点:可以非常方便的遍历整个容器中的对象序列,而不用关心底层的结构是什么。此外迭代器被称为轻量级对象:创建它的代价很小。5、 内部类的作用概念:定义在另一个类的定义的内部的类叫做内部类。作用:允许你把一些逻辑相关的类组织在一起,并控制位于内部的类的可视性。内部类还是一种代码隐藏机制,更重要的是,它了解外围类,并能与之通信;1.内部类可以很好的实现隐藏,一般的非内部类是不允许有 private 与protected权限的,但内部类可以2.内部类拥有外围类的所有元素的访问权限 3.可以实现多重继承 4.可以避免修改接口而实现同一个类中两种同名方法的调用。6、 类加载器的作用 通过一个类的全限定名来获取定义此类的二进制字节流这个动作是在Java虚拟机外部来实现的,以便让应用程序自己决定如何去获取所需要的类。实现这个动作的代码模块被称为“类加载器”。7、 设计和实现图形用户界面的工作主要有哪几方面? 搭界面:创建组成界面的各个元素,指定它们的属性和位置关系,从而构成完整的GUI外观。写代码:定义好各个界面元素对不同事件的响应,从而实现GUI与用户的交互功能。 首先要了解可以设计图形用户的各种组件以及用法利用布局管理器在窗体上巧妙布局,并且给界面美工绑定相应的事件模型,例如常见的动作事件、鼠标事件、键盘事件等等。编程题的复习重点:1) 创建一个名为Amphibian的类。由此继承产生一个称为Frog 的类。在基类中设置适当的方法。在main( )中,创建一个Frog并向上转型至Amphibian,然后说明所有方法都可以工作。(P140-16)class Amphibian protected void swim() System.out.println(Amphibian swim);protected void speak() System.out.println(Amphibian speak);void eat() System.out.println(Amphibian eat);static void grow(Amphibian a) System.out.println(Amphibian grow);a.eat();public class Frog extends Amphibian public static void main(String args) Frog f = new Frog();/ call base-class methods:f.swim();f.speak();f.eat();/ upcast Frog to Amphibian argument:Amphibian.grow(f);/*Output:Amphibian swimAmphibian speakAmphibian eatAmphibian growAmphibian eat2) 编写一个名为Outer的类,它包含一个名为Inter的类。在Outer中添加一个方法,它返回一个Inter类型的对象。在main( )中,创建并初始化一个指向某个Inter对象的引用。(p191-1)public class Outer1 class Inner Inner() System.out.println(Inner(); Outer1() System.out.println(Outer1(); / make an Inner from within a non-static method of outer class:Inner makeInner() return new Inner();public static void main(String args) Outer1 o = new Outer1();Inner i = o.makeInner();/*Output:Outer1()Inner()3) 创建一个Cycle类,它具有子类Unicycle、Bicycle和Tricycle,实现每一个类型的实例都可以经由ride( )方法向上转型为Cycle。class Cycle private String name = Cycle;public static void travel(Cycle c) System.out.println(Cycle.ride() + c);public String toString() return ;class Unicycle extends Cycle private String name = Unicycle;public String toString() return ;class Bicycle extends Cycle private String name = Bicycle;public String toString() return ;class Tricycle extends Cycle private String name = Tricycle;public String toString() return ;public class Biking public static void ride(Cycle c) (c);public static void main(String args) Unicycle u = new Unicycle();Bicycle b = new Bicycle();Tricycle t = new Tricycle();ride(u);ride(b);ride(t);/*Output:Cycle.ride() UnicycleCycle.ride() BicycleCycle.ride() Tricycle4) 编写一个类名为chap的应用程序,用于演示JButton按钮操作,当单击左边的按钮时,中间的按钮和左边的按钮将失效,当右边的按钮由失效变成有效. import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Chap public static void main(String args) Frame frame = new Frame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); class Frame extends JFrame public Frame() setTitle(Chap); Panel panel = new Panel(); add(panel);pack(); class Panel extends JPanel JButton display; JButton left_button = new JButton(左边); JButton mid_button = new JButton(中间); JButton right_button = new JButton(右边); private JPanel panel; private static final long serialVersionUID = 1L; public Panel() setLayout(new BorderLayout(); LeftAction left = new LeftAction(); MidAction mid = new MidAction(); RightAction right = new RightAction(); panel = new JPanel(); panel.setLayout(new GridLayout(1, 4); left_button.addActionListener(left); panel.add(left_button); mid_button.addActionListener(mid); panel.add(mid_button); right_button.addActionListener(right); panel.add(right_button); add(panel, BorderLayout.CENTER); private class LeftAction implements ActionListener public void actionPerformed(ActionEvent event) display.setText(您点击的是左边的按钮!); private class MidAction implements ActionListener public void actionPerformed(ActionEvent event) display.setText(您点击的是中间的按钮!); private class RightAction implements ActionListener public void actionPerformed(ActionEvent event) display.setText(您点击的是右边的按钮!); /*Output:5) 编写一个应用程序,它包括一个文本域和三个按钮,单击每个按钮时在文本区显示不同的文字。import java.awt.event.*;import java.awt.*;import javax.swing.*;public class Button3 extends JFrameprivate JButton button1=new JButton(button1),button2=new JButton(button2),button3=new JButton(button3);private JTextField txtf=new JTextField(10);public static void run(final JFrame f,final int width,final int height)SwingUtilities.invokeLater(new Runnable()public void run() / TODO Auto-generated method stubf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setTitle(f.getClass().getSimpleName();f.setSize(width, height);f.setVisible(true););private ActionListener bl=new ActionListener()public void actionPerformed(ActionEvent e) String name=(JButto)e.getSource().getText();txtf.setText(name);public Button3()button1.addActionListener(bl);button2.addActionListener(bl);button3.addActionListener(bl);setLayout(new FlowLayout();add(button1);add(button2);add(button3);add(txtf);public static void main(String args) / TODO Auto-generated method stubrun(new Button3(), 400, 300);/*Output:6) 、编写程序实现以下继承关系:动物类派生出鸟类、鱼类,鸟类派生出燕子类,鱼类派生出鲨鱼类。要求:每个类包含域“类别”、方法“返回类别”请读懂以下程序并给出运行结果:/程序1public class Guess /* * param args */public static void main(String args) / TODO Auto-generated method stub int a,b; for(a=14;a=90;a+) for(b=11;b50;b+) if(a-10)=(b-10)*4)&(a+10)%(b+10)=0) System.out.println(ag +a+ daf+b); /*Output:ag 50 daf20/程序2class OverrideDemo void test() System.out.println( No parameters ); void test(int a) System.out.println(a: + a); void test(int a,int b) System.out.println(a and b: + a + + b); void test(double a) System.out.println(double a: + a);Public class Override public static void main(String args) OverrideDemo ob = new OverrideDemo(); ob.test(); ob.test(10); ob.test(10,20); ob.test(123.25); /*Output:No parameters a: 10a and b:10 20double a: 123.25/程序3import java.awt.*;import java.awt.event.*;import java.applet.*;public class ButtonApplet extends Applet implements ActionListener int i1,i2; Button btn1,btn2; public void init() i1=0; i2=0; btn1=new Button(确定); btn2=new Button(取消); add(btn1); add(btn2); btn1.addActionListener(this); btn2.addActionListener(this); public void paint(Graphics g) g.setColor(Color.blue); g.drawString(你点击了确定+ i1+次,20,100); g.setColor(Color.red); g.drawString(你点击了确定+ i2+次,20,120); public void actionPerformed(ActionEvent e) if(e.getSource()=btn1) i1+; if(e.getSource()=btn2) i2+; repaint(); /*Output:/程序4interface WeaponString name = weapon;void attack();class Tank implements Weaponpublic void attack()System.out.println(Tank attack);class Cannon implements Weaponpublic void attack()System.out.println(Cannon attack);class testWeaponpublic static void main(String args)Weapon wp; wp = new Tank();wp.attack();wp = new Cannon();wp.attack();/*Output:Tank attackCannon attack/程序5public class Parcel2 class Contents private int i=11; public int value()return i; class Destination private String lable; Destination(String whereTo) lable=whereTo; String readLabel()return lable; public Destination to(String s) return new Destination(s); public Contents contents() return new Contents(); public void ship(String dest) Contents c=contents(); Destination d=to(dest); System.out.println(d.readLabel(); public static void main(String args) Parcel2 p=new Parcel2();p.ship(Tasmania);Parcel2 q=new Parcel2();Parcel2.Contents c=q.contents();Parcel2.Destination d=q.to(Borneo);/*Output:Tasmania/程序6:import java.util.*;public class SimpleCollection public static void main(String args) int b=0;Collection c=new ArrayList(); for(int i=0;i10;i+) b=i+3; c.add(b); for(Integer i:c) System.out.print(i+ );/*Output:12 /程序7:class WindowWindow(int marker)System.out.print(Window(+marker+);class HouseWindow w1=new Window(1);House()System.out.print(House();w3=new Window(33);Window w2=new Window(2);void f()System.out.print(f();Window w3=new Window(3);public class orderOfInitialization public static void main(String args) House h=new House();h.f();/*Output:Window(1)Window(2)Window(3)House()Window(33)f()/程序8public class ko public static void main(String args) int t, z=10; t=sum(z); System.out.println(sum=+t); static int sum(int x) if(x=1) return(1); else return(sum(x-1)+x);/*Output:sum=55/程序9public class TextComponetEvent extends Applet implements TextListener,ActionListener TextField tf; TextArea ta; public void init() tf=new TextField(45); ta=new TextArea(5,45); add(tf); add(ta); tf.addActionListener(this); tf.addTextListener(this); public void textValueChanged(TextEvent e) if(e.getSource()=tf) ta.setText(TextField)e.getSource().getText(); public void actionPerf

温馨提示

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

评论

0/150

提交评论