资源预览内容
第1页 / 共5页
第2页 / 共5页
第3页 / 共5页
第4页 / 共5页
第5页 / 共5页
亲,该文档总共5页全部预览完了,如果喜欢就下载吧!
资源描述
第五次作业1、Window、Dialog、Frame窗体默认的布局管理器是BorderLayout Panel、小应用程序默认的布局管理器是 FlowLayout 当添加两个或两个以上的用来处理同一个事件的监听器时,首先被调用的监听器是那一个?随机,不确定。现有实现了ActionListener接口的事件监听器类X和一个按钮,用什么语句为按钮注册一个Action事件监听器? addActionListener(new X( )2、在Java中最基本的类是 Object 3、要使某个类能被同一个包中的其他类访问,不能被这个包以外的类访问,可以使用关键字定义 让该类不使用任何关键字 。4、Runnable接口中定义的方法为 run( )方法 5、哪些修饰符能用于顶层类 abstract、public、final 6、阐述线程的状态及生命周期? (1)新建状态(2)就绪状态(3)运行状态(4)阻塞状态 :A、位于对象等待池中的阻塞状态 B、位于对象锁池中的阻塞状态 C、其他阻塞状态:当前线程执行了sleep( )方法、或者调用其他线程的join( )方法、或者发出I/O请求时,就会进入这个状态(5)死亡状态7、接口包含的方法既可以有实现,也可以没有实现这个说法正确么? 当类被关键字final修饰时,这个能否被继承?答: 接口包含的方法既可以有实现,也可以没有实现这个说法不对; 当类被关键字final修饰时,这个不能被继承8、分析以下程序,指出错误的地方并改正 class A implements Runnablepublic static void main(String args)Thread t=new Thread(this);/ Thread t=new Thread(new Runnable( )t.start();public void run(int j )/Runnable接口中的run( )方法实现错误for(int i=0;ij;i+)System.out.println(hi);错误原因:1.不能在静态方法中使用this; 2. Runnable接口中的run( )方法实现错误改正: Thread t=new Thread(this);改为Thread t=new Thread(new A(); Public void run(int j)改为public void run();里面的j改为一个整数.9、请指出错误并改正。public class Sxamplefinal String s= outter variable ;public void Method()int i1=15;class InClasspublic void innerMethod()System.out.println(s);System.out.println(i1);错误原因:内部类不能直接访问所在方法的非final变量:改正: int i1=15;改为final int i1=15;10、请指出错误并改正。public class Samplepublic static void main(String args )Boolean b=new Boolean(TRUE);if(b)for(Integer i=0;i10;i+)System.out.println(i);错误原因:不能将对象引用当基本类型使用;改正: Boolean b=new Boolean(TRUE);改为boolean b=true;11、写出下面程序的输出结果。public class Astatic String str=aaa;A()str=ccc;System.out.println(str);System.out.println(str);public static void main(String args)A obj=new A( );System.out.println(obj.str);System.out.println(str);输出结果:aaa ccc ccc ccc12、写出下面程序的输出结果。(4分)public class Samplepublic static void change(String str)str=It is Changed;public static void main(String args)String str=new String(Hello);change(str);System.out.println(str); 输出结果:Hello13、写出下面程序的输出结果。class BaseBase()System.out.println(Message 1:In the base class constructor);abstract class Sub1 extends Base/abstract起什么作用? Sub1()System.out.println(Message 2:In the abstract Sub1s class constructor); class Sub2 extends Sub1 Sub2()System.out.println(Message 3:In the Sub2s class constructor);public static void main(String args) System.out.println(This is a test.);Sub2 d2=new Sub2();输出结果: Message 1:In the abstract Sub1s class constructor Message 2:In the abstract Sub1s class constructor Message 3:In the Sub2s class constructor14、写出下面程序的输出结果。public class Demostatic String str=hello;Demo()str=people;System.out.print(str+ );System.out.print(str+ );public static void main(String args)Demo obj=new Demo( );System.out.print(obj.str+ );System.out.print(str+ );输出结果:hello people people people15、写出下面程序的输出结果。(4分)public class Example_13public void method(Object o)System.out.println(Object Version);public void method(String s)System.out.println(String Version);public static void main(String args)Example_13 exm=new Example_13( );exm.method(null);输出结果: String Version16、以下程序段执行的结果为(c) public class Example_7public static void main(String args)Boolean b1=new Boolean(true);Boolean b2=new Boolean(true);if(b1=b2) if(b1.equals(b2) System.out.println(a); else System.out.println(b);else if(b1.equals(b2) System.out.println(c); else System.out.println(d);输出结果:c
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号