java语言程序设计e中国大学mooc完整答案-买球的app软件下载

1885 人参与  2023-01-04 05:38:21    点这评论
复习测试

复习测试

1、what is best to describe the relationship between component and font?
    a、association
    b、aggregation
    c、composition
    d、inheritance
    e、244

2、下面三个表达式中,正确的是 ___________. 1. frame.setlocationrelativeto(null); 2. frame.setsize(100, 200); 3. frame.setvisible(true);
    a、1 2 3
    b、1 3 2
    c、2 1 3
    d、3 2 1
    e、245

3、how many frames are displayed? import javax.swing.*; public class test extends jframe { public static void main(string[] args) { jframe f1 = new test(); jframe f2 = new test(); jframe f3 = new test(); f1.setvisible(true); f2.setvisible(true); f3.setvisible(true); } }
    a、1
    b、2
    c、3
    d、0
    e、246

4、jpanel的缺省布局方式是__________________.
    a、flowlayout
    b、gridlayout
    c、borderlayout
    d、none
    e、247

5、方法________________将给jpanel p增加一个组件 c。
    a、p.add(c)
    b、p.getcontentpane(c)
    c、p.insert(c)
    d、p.append(c)
    e、248

6、analyze the following code: import javax.swing.*; public class test extends jframe { private jbutton jbtok = new jbutton("ok"); public static void main(string[] args) { // create a frame and set its properties jframe frame = new test(); frame.settitle("logic error"); frame.setsize(200, 100); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setvisible(true); } public test() { jbtok.settooltiptext("this is a button"); add(new jbutton("ok")); } }
    a、the tool tip text is displayed when you move the mouse on the button.
    b、the tool tip text will be displayed if you replace add(new jbutton("ok")) with add(jbtok).
    c、the tool tip text will be displayed if you swap the two lines in the test constructor.
    d、the tool tip text will be displayed if you replace add(new jbutton("ok")) with add(jbtok = new jbutton("ok")).
    e、249

7、show the output of the following code? import javax.swing.*; public class test { public static void main(string[] args) { jbutton jbtok = new jbutton("ok"); system.out.print(jbtok.isvisible() ", "); jframe frame = new jframe(); system.out.println(frame.isvisible()); } }
    a、true, true
    b、true, false
    c、false, true
    d、false, false
    e、250

8、方法_________设置按钮jbt上的文字放在图标的右边。
    a、jbt.setverticaltextposition(jbutton.left)
    b、jbt.sethorizontaltextposition(jbutton.left)
    c、jbt.sethorizontaltextposition(jbutton.right)
    d、jbt.sethorizontalalignment(jbutton.right)
    e、251

9、the method __________ specifies that the text and icon are horizontally aligned to the right in the button jbt.
    a、jbt.setverticaltextposition(jbutton.left)
    b、jbt.sethorizontaltextposition(jbutton.left)
    c、jbt.sethorizontaltextposition(jbutton.right)
    d、jbt.sethorizontalalignment(jbutton.right)
    e、252

10、analyze the following code: import javax.swing.*; import javax.swing.border.*; import java.awt.*; public class test extends jframe { public test() { border border = new titledborder("my button"); jbutton jbt1 = new jbutton("ok"); jbutton jbt2 = new jbutton("cancel"); jbt1.setborder(border); jbt2.setborder(border); add(jbt1, borderlayout.north); add(jbt2, borderlayout.south); } public static void main(string[] args) { jframe frame = new test(); frame.setsize(200, 100); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setvisible(true); } }
    a、two buttons displayed with the same border.
    b、two buttons displayed, but only one button has the border.
    c、the program has a compile error because you assign new titledborder("my button") to a variable of the border type.
    d、the program has a runtime error because you cannot set a border on a button.
    e、253

11、方法___________将获取标签jlbl上的文本。
    a、jlbl.text()
    b、jlbl.gettext()
    c、jlbl.findtext()
    d、jlbl.retrievetext().
    e、254

12、the method __________ specifies that the text is placed on the right of the icon in the label jlbl.
    a、jlbl.setverticaltextposition(jbutton.left)
    b、jlbl.sethorizontaltextposition(jbutton.left)
    c、jlbl.sethorizontaltextposition(jbutton.right)
    d、jlbl.sethorizontalalignment(jbutton.right)
    e、255

13、___________能够输入或者显示一个字符串。
    a、a label
    b、a button
    c、a check box
    d、radio button
    e、256

14、一个字节包含 ________ 位
    a、4
    b、8
    c、12
    d、16
    e、1

15、方法__________用来获取文本控件jtf上的内容。
    a、jtf.gettext(s)
    b、jtf.gettext()
    c、jtf.getstring()
    d、jtf.findstring()
    e、257

16、which of the following statements is correct?
    a、every line in a program must end with a semicolon
    b、every statement in a program must end with a semicolon
    c、every comment line must end with a semicolon
    d、every method must end with a semicolon
    e、2

17、the method __________ appends a string s into the text area jta.
    a、jta.settext(s)
    b、jta.appendtext(s)
    c、jta.append(s)
    d、jta.inserttext(s)
    e、258

18、java字节码文件的后缀是
    a、.java
    b、.obj
    c、.class
    d、.exe
    e、3

19、to wrap a line in a text area jta, invoke ____________.
    a、jta.setlinewrap(false)
    b、jta.setlinewrap(true)
    c、jta.wrapline()
    d、jta.wraptext()
    e、259

20、java ___________ can run from a web browser
    a、applications
    b、applets
    c、servlets
    d、micro edition programs
    e、4

线程测验

1、编写线程类,要继承的父类是 ( )
    a、thread
    b、runnable
    c、serializable
    d、exception

2、以下哪个最准确地描述了 synchronized 关键字?
    a、保证在某时刻只有一个线程可访问方法或对象
    b、保证两个或更多线程同时开始和结束
    c、保证允许两个或更多处理同时开始和结束
    d、允许两线程并行运行,而且互相通信

3、下列说法中错误的一项是( )
    a、线程操作的数据来自runnable实例
    b、新建的线程调用start()方法就能立即进入运行状态
    c、线程从传递给它的runnable实例的run()方法开始执行
    d、一个线程是一个thread类的实例

4、在java多线程中,请用下面哪种方式不会使线程进入阻塞状态?
    a、sleep()
    b、suspend()
    c、wait()
    d、yield()

5、关于arraylist 和 vector 的区别,以下说法正确的是 ( )
    a、arraylist是线程安全的,vector是线程不安全的
    b、arraylist底层是链表结构,vector底层是数组结构
    c、arraylist底层是数组结构,vector底层是链表结构
    d、arraylist是线程不安全的,vector是线程安全的

6、有以下代码: public class testmultithread { public static void main(string[] args) { thread t = new thread() { public void run(){ pong(); } }; t.run(); system.out.println("ping"); } static void pong(){ system.out.println("pong"); } } 请问程序的运行结果是( )?
    a、pong ping
    b、ping ping
    c、ping 和 pong 的输出顺序不确定,取决于线程的执行顺序
    d、都不输出

7、若要启动一个线程,必须调用 ( ) 方法。
    a、new
    b、run
    c、start
    d、resume

8、下列哪一种情况不会终止当前线程的运行?
    a、当创建一个新线程时
    b、当该线程调用 sleep 方法时
    c、抛出一个异常时
    d、当一个优先级更高的线程进入就绪状态时

9、下面所述步骤中,创建进程做必须的步骤包括( )
    a、为进程分配内存
    b、为进程分配文件描述符
    c、建立一个进程控制块
    d、由调度程序为进程分配 cpu

10、以下( ) 方法可以用来暂时停止当前线程的运行。
    a、stop()
    b、sleep()
    c、wait()
    d、suspend()

异常测验

1、给出如下代码段: try { int x = integer.parseint("two"); } 下列哪个可以作为catch的异常?
    a、classcastexception
    b、illegalstateexception
    c、numberformatexception
    d、exceptionininitializererror

2、给出下列代码: class plane { static string s = "-"; public static void main(string[] args){ new plane().s1(); system.out.println(s); } void s1() { try {s2();}catch (exception e){  s  = "c";  } } void s2() throws exception { s3();  s  = "2"; s3(); s  = "2b"; } void s3() throws exception{ throw new exception(); } } 结果是什么?
    a、-
    b、-c
    c、-c2
    d、-2c

3、下列程序的执行,说法正确的是( ) class multicatch { public static void main(string args[]) { try { int a=args.length; int b=42/a; int c[]={1}; c[42]=99; //10行 system.out.println(“b=” b); } catch(arithmeticexception e) { system.out.println(“除0异常:” e); //15行 } catch(arrayindexoutofboundsexception e) { system.out.println(“数组超越边界异常:” e); //19行 } } }
    a、程序将输出第15行的异常信息
    b、程序第10行出错
    c、程序将输出“b=42”
    d、程序将输出第19行的异常信息

4、下面是一些异常类的层次关系: java.lang.exception java.lang.runtimeexception java.lang.indexoutofboundsexception java.lang.arrayindexoutofboundsexception java.lang.stringindexoutofboundsexception 假设有一个方法x,能够抛出两个异常,array index和string index异常,假定方法x中没有try-catch语句处理这些异常,下面哪个答案是正确的?( )
    a、方法x 应该声明抛弃arrayindexoutofboundsexception和stringindexoutofbounds-exception。
    b、如果调用x的方法捕获indexoutofboundsexception,则arrayindexoutofboundsexception和stringindexoutofboundsexception都可以被捕获。
    c、如果方法x声明抛弃indexoutofboundsexception,则调用x的方法必须用try-catch语句捕获。
    d、方法x不能声明抛弃异常。

5、请问所有的异常(exception)和错误(error)类皆继承哪一个类?( )
    a、java.lang.throwable
    b、java.lang.exception
    c、java.lang.error
    d、java.io.exception

6、pubic void test () { try { onemethod (); system.out.print ( "condition 1"); } catch ( exception e ) { system.out.print ( "condition 3"); } catch ( arithmeticexception e ) { system.out.print ( "condition 2" ); } finally { system.out.println ("condition 4" ); } } which will display if onemethod throw nullpointerexception?
    a、condition 1 condition4
    b、condition 2 condition4
    c、condition 3 condition4
    d、error in compilation

7、given: import java.io.*; class master { string dofilestuff() throws filenotfoundexception {  return "a";  } } class slave extends master { public static void main(string[] args){ string s = null; try {  s = new slave().dofilestuff();}catch ( exception x){ s = "b";  } system.out.println(s); } // insert code here } which, inserted independently at // insert code here, will compile, and produce the output b? (choose all that apply.)
    a、string dofilestuff() { return "b"; }
    b、string dofilestuff() throws ioexception { return "b"; }
    c、string dofilestuff(int x) throws ioexception { return "b"; }
    d、string dofilestuff() throws exception { return "b"; }

8、given import java.io.*; class main{ public void f1() throws arithmeticexception{} public void f2() throws filenotfoundexception{} public static void main(){ new main().f1(); //line1 new main().f2(); //line2 } } which is correct?
    a、no error in compilation
    b、error at //line1 in compilation
    c、error at //line2 in compilation
    d、two errors at //line1 and //line2 in compilation

9、class emu{ static string s = "-"; public static void main(string[] args){ try{ throw new exception(); }catch(exception e){ try{ try{ throw new exception(); }catch (exception ex){ s = "ic "; } throw new exception(); } catch(exception x){ s = "mc "; } finally{ s = "mf "; } }finally{ s = "of "; } system.out.println(s); } } what is the result?
    a、-ic mf of
    b、-ic mc mf of
    c、-ic mc of mf
    d、compilation fails

10、given: class mineral{ } class gem extends mineral{ } class miner{ static int x = 7; static string s = null; public static void getweight(mineral m){ int y = 0 / x; system.out.print(s " "); } public static void main(string[] args){ mineral[] ma = {new mineral(), new gem()}; for(object o : ma) getweight((mineral) o); } } and the command-line invocation: java miner what is the result?
    a、null
    b、null null
    c、a classcastexception is thrown.
    d、a nullpointerexception is thrown.

复习测验1

1、the signature of a method consists of ________
    a、method name
    b、method name and parameter list
    c、return type, method name, and parameter list
    d、parameter list

2、suppose your method does not return any value, which of the following keywords can be used as a return type?
    a、void
    b、int
    c、double
    d、none of the above

3、suppose you wish to provide an accessor method for a boolean property finished, what signature of the method should be?
    a、public void getfinished()
    b、public boolean getfinished()
    c、public boolean isfinished()
    d、public void isfinished()

4、suppose the xmethod() is invoked from a main method in a class as follows, xmethod() is _________ in the class. public static void main(string[] args) { xmethod(); }
    a、a static method
    b、an instance method
    c、a static method or an instance method
    d、an object method

5、given: 3. public class dark { 4. int x = 3; 5. public static void main(string[] args) { 6. new dark().go1(); 7. } 8. void go1() { 9. int x; 10. go2( x); 11. } 12. void go2(int y) { 13. int x = y; 14. system.out.println(x); 15. } 16. } what is the result?
    a、3
    b、4
    c、5
    d、compilation fails

6、given: 1. public class yippee { 2. public static void main(string [] args) { 3. for(int x = 1; x < args.length; x ) { 4. system.out.print(args[x] " "); 5. } 6. } 7. } and two separate command line invocations: java yippee java yippee 1 2 3 4 what is the result?
    a、no output is produced. 1 2 3
    b、no output is produced. 2 3 4
    c、no output is produced. 1 2 3 4
    d、an exception is thrown at runtime. 1 2 3

7、given: 1. public class pass { 2. public static void main(string [] args) { 3. int x = 5; 4. pass p = new pass(); 5. p.dostuff(x); 6. system.out.print(" main x = " x); 7. } 8. 9. void dostuff(int x) { 10. system.out.print(" dostuff x = " x ); 11. } 12. } what is the result?
    a、dostuff x = 6 main x = 6
    b、dostuff x = 5 main x = 5
    c、dostuff x = 5 main x = 6
    d、dostuff x = 6 main x = 5

8、given: 1. public class frodo extends hobbit { 2. public static void main(string[] args) { 3. short mygold = 7; 4. system.out.println(countgold(mygold, 6)); 5. } 6. } 7. class hobbit { 8. int countgold(int x, int y) { return x y; } 9. } what is the result?
    a、13
    b、compilation fails due to multiple errors
    c、compilation fails due to an error on line 1
    d、compilation fails due to an error on line 4

9、given: 1. public class batman { 2. int squares = 81; 3. public static void main(string[] args) { 4. new batman().go(); 5. } 6. void go() { 7. incr( squares); 8. system.out.println(squares); 9. } 10. void incr(int squares) { squares = 10; } 11. } what is the result?
    a、81
    b、82
    c、91
    d、92

10、given: 1. class voop { 2. public static void main(string[] args) { 3. dostuff(1); 4. dostuff(1,2); 5. } 6. // insert code here 7. } which, inserted independently at line 6, will compile?
    a、static void dostuff(int... doargs) { }
    b、static void dostuff(int[] doargs) { }
    c、static void dostuff(int doargs...) { }
    d、static void dostuff(int... doargs, int y) { }

11、given: 1. class voop { 2. public static void main(string[] args) { 3. dostuff(1); 4. dostuff(1,2); 5. } 6. // insert code here 7. } self test answers 79 80 chapter 1: declarations and access control which, inserted independently at line 6, will compile?
    a、static void dostuff(int... doargs) { }
    b、static void dostuff(int[] doargs) { }
    c、static void dostuff(int doargs...) { }
    d、static void dostuff(int... doargs, int y) { }

12、given the following code what will be output? public class pass{ static int j=20; public static void main(string argv[]){ int i=10; pass p = new pass(); p.amethod(i); system.out.println(i); system.out.println(j); } public void amethod(int x) { x=x*2; j=j*2; } }
    a、error: amethod parameter does not match variable
    b、20 and 40
    c、10 and 40
    d、10 and 20

13、analyze the following code: class test { public static void main(string[] args) { system.out.println(xmethod((double)5)); } public static int xmethod(int n) { system.out.println("int"); return n; } public static long xmethod(long n) { system.out.println("long"); return n; } }
    a、the program displays int followed by 5
    b、the program displays long followed by 5
    c、the program runs fine but displays things other than given in a and b
    d、the program does not compile

14、analyze the following code: public class test { public static void main(string[] args) { system.out.println(xmethod(5, 500l)); } public static int xmethod(int n, long l) { system.out.println("int, long"); return n; } public static long xmethod(long n, long l) { system.out.println("long, long"); return n; } }
    a、the program displays int, long followed by 5
    b、the program displays long, long followed by 5
    c、the program runs fine but displays things other than 5
    d、the program does not compile because the compiler cannot distinguish which xmethod to invoke

15、analyze the following code. public class test { public static void main(string[] args) { int n = 2; xmethod(n); system.out.println("n is " n); } void xmethod(int n) { n ; } }
    a、the code has a compile error because xmethod does not return a value
    b、the code has a compile error because xmethod is not declared static
    c、the code prints n is 2
    d、the code prints n is 3

16、all java applications must have a method ______
    a、public static main(string[] args)
    b、public static main(string args[])
    c、public static void main(string[] args)
    d、none of the above

17、a variable defined inside a method is referred to as _____
    a、a global variable
    b、a method variable
    c、a block variable
    d、a local variable

18、a method that is associated with an individual object is called ____
    a、a static method
    b、a class method
    c、an instance method
    d、an object method

19、有以下方法的定义,请选择该方法的返回类型 returntype method(byte x, double y) { return (short)x/y*2; }
    a、byte
    b、short
    c、int
    d、double

20、which of the following statements are correct?
    a、char[][] chararray = {'a', 'b'};
    b、char[2][2] chararray = {{'a', 'b'}, {'c', 'd'}};
    c、char[2][] chararray = {{'a', 'b'}, {'c', 'd'}};
    d、char[][] chararray = {{'a', 'b'}, {'c', 'd'}};

21、suppose a method p has the following heading: public static int[] p() what return statement may be used in p()?
    a、return 1;
    b、return {1, 2, 3};
    c、return int[]{1, 2, 3};
    d、return new int[]{1, 2, 3};

22、if you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is ________
    a、0
    b、3
    c、4
    d、5

23、for-each loop) analyze the following code: public class test { public static void main(string[] args) { double[] x = {2.5, 3, 4}; for (double value: x) system.out.print(value " "); } }
    a、the program displays 2.5, 3, 4
    b、the program displays 2.5 3 4
    c、the program displays 2.5 3.0 4.0
    d、the program displays 2.5, 3.0 4.0

24、analyze the following code: public class test { public static void main(string[] args) { int[] x = {1, 2, 3, 4}; int[] y = x; x = new int[2]; for (int i = 0; i < y.length; i ) system.out.print(y[i] " "); } }
    a、the program displays 1 2 3 4
    b、the program displays 0 0
    c、the program displays 0 0 3 4
    d、the program displays 0 0 0 0

25、执行完以下代码int [ ] x = new int[25];后,以下哪项说明是正确的( )
    a、x[24]为0
    b、x[24]未定义
    c、x[25]为0
    d、x[0]为空

26、有关类demo,哪句描述是正确的? ( ) public class demo extends base{ private int count; public demo(){ system.out.println("a demo object has been created"); } protected void addone() {count ;} }
    a、当创建一个demo类的实例对象时,count的值为0
    b、当创建一个demo类的实例对象时,count的值是不确定的.
    c、超类对象中可以包含改变count 值的方法。
    d、demo的子类对象可以访问count。

27、以下说法错误的是【 】
    a、applet小应用程序不可以独立运行
    b、一个java源程序可以没有public修饰的类
    c、在一个java源程序中可以定义多个类
    d、一个java源程序可以有多个public修饰的类

28、以下说法不正确的是【 】
    a、private修饰的成员变量可以在本类或其本包中子类中使用
    b、java类可以同时实现多个接口,但只能继承一个父类
    c、static修饰的成员变量可以不经过实例化直接通过类名引用
    d、static不可以和abstract修饰符同时使用

29、以下哪个类能正确编译?【 】
    a、class a{ abstract void disp(); }
    b、abstract class a{ void disp(){ system.out.println("welcome to beijing!"); } }
    c、class a{ abstract void disp(){ system.out.println("welcome to beijing!"); } }
    d、abstract class a{ final abstract void disp(); }

30、已知在一个类中能正确使用命令:import hr.tech.wage。以下说法不正确的是【 】
    a、wage是类名
    b、在wage类中声明包的命令是package hr.tech
    c、hr.tech.wage是包名
    d、不使用import hr.tech.wage语句,也可使用new hr.tech.wage()的方式产生对象

复习测验2

1、要想定义一个不能被实例化的抽象类,在类定义中必须加上修饰符( )。
    a、final
    b、public
    c、private
    d、abstract

2、下述说法中,错误的是
    a、java中,方法的重载是指多个方法可以共享同一个名字
    b、java中,用abstract修饰的类称为抽象类,它不能实例化
    c、java中,接口不包含方法实现
    d、java中,构造方法可以有返回值

3、下面哪个函数不是public void example(){...}的重载函数【 】
    a、public void example( int m){...}
    b、public int example(){...}
    c、public void example(float f){...}
    d、public int example ( int m, float f){...}

4、下列哪一种叙述是正确的( )
    a、abstract修饰符可修饰字段、方法和类
    b、抽象方法的body部分必须用一对大括号{ }包住
    c、声明抽象方法,大括号可有可无
    d、声明抽象方法不可写出大括号

5、下列关于修饰符混用的说法,错误的是( )
    a、abstract不能与final并列修饰同一个类
    b、abstract类中不可以有private的成员
    c、abstract方法必须在abstract类中
    d、static方法中能处理非static的属性

6、为ab类的一个无形式参数无返回值的方法method书写方法头,使得使用类名ab作为前缀就可以调用它,该方法头的形式为( )。
    a、static void method( )
    b、public void method( )
    c、final void method( )
    d、abstract void method( )

7、如果类中的成员变量可以被同一包访问,则使用如下哪个约束符【 】
    a、private
    b、public
    c、protected
    d、缺省约束符

8、类test1定义如下: 1.public class test1{ 2. public float amethod(float a,float b){ } 3. 4.} 将以下哪种方法插入行3是不合法的。( )
    a、public float amethod(float a, float b,float c){ }
    b、public float amethod(float c,float d){ }
    c、public int amethod(int a, int b){ }
    d、private float amethod(int a,int b,int c){ }

9、设已声明了一个类a的两个对象a1,a2,为了初始化 a1和a2,下面语句正确的是
    a、a1,a2=new a();
    b、a1=a.new(); a2=a.new();
    c、a1=new();a2=new();
    d、a1=new a();a2=new a();

10、关于以下说法,描述错误的是【 】
    a、在java应用程序中main方法里,不能直接使用非静态变量
    b、有abstract修饰的类能够直接实例化
    c、一个非抽象类实现一个接口,在该类中必须重写该接口中所有的方法
    d、this和super这两个特殊变量只能用在非静态方法中

11、若java程序中定义了3个类,编译后可生成(   )个字节码文件。
    a、4
    b、3
    c、2
    d、1

12、关于以下程序代码的说明正确的是( ) 1. class hasstatic{ 2. private static int x=100; 3. public static void main(string args[ ]){ 4. hasstatic hs1=new hasstatic( ); 5. hs1.x ; 6. hasstatic hs2=new hasstatic( ); 7. hs2.x ; 8. hs1=new hasstatic( ); 9. hs1.x ; 10. hasstatic.x- -; 11. system.out.println("x=" x); 12. } 13. }
    a、5行不能通过编译,因为引用了私有静态变量
    b、10行不能通过编译,因为x是私有静态变量
    c、程序通过编译,输出结果为:x=103
    d、程序通过编译,输出结果为:x=102

13、哪个关键字修饰的变量和方法不能从其他类访问?
    a、protected
    b、public
    c、private
    d、default

14、关于被私有访问控制符private修饰的成员变量,以下说法正确的是
    a、可以被三种类所引用:该类自身、与它在同一个包中的其他类、在其他包中的该类的子类
    b、可以被两种类访问和引用:该类本身、该类的所有子类
    c、只能被该类自身所访问和修改
    d、只能被同一个包中的类访问

15、哪个关键字声明一个常量?
    a、protected
    b、static
    c、final
    d、default

16、关于被保护访问控制符protected修饰的成员变量,以下说法正确的是
    a、可以被三种类所引用:该类自身、与它在同一个包中的其他类、在其他包中的该类的子类
    b、可以被两种类访问和引用:该类本身、该类的所有子类
    c、只能被该类自身所访问和修改
    d、只能被同一个包中的类访问

17、哪个表达式的结果为0.5?
    a、1 / 2
    b、(double) (1 / 2)
    c、(double) 1 / 2
    d、1 \ 2

18、给定以下代码 3. public class testdays { 4. public enum days { mon, tue, wed }; 5. public static void main(string[] args) { 6. for(days d : days.values() ) 7. ; 8. days [] d2 = days.values(); 9. system.out.println(d2[2]); 10. } 11. } 结果正确的是?
    a、tue
    b、wed
    c、输出不可预料
    d、编译错

19、不是构造函数特点的是( )
    a、构造函数与类名相同
    b、构造函数可带参数也可不带
    c、构造函数带有返回类型
    d、构造函数主要完成对类对象的初始工作

20、给出下面的代码段 public class base{ int w, x, y ,z; public base(int a,int b) { x=a; y=b; } public base(int a, int b, int c, int d){ ________________ w=d; z=c; } } 在代码说明________处写入如下哪一个代码是正确的?【 】
    a、a=x; b=y;
    b、x=a, y=b;
    c、super(a,b)
    d、this(a,b)

21、编译java application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为( )。
    a、.java
    b、.class
    c、.obj
    d、.jdk

22、不允许作为类及类成员的访问控制符的是( )。
    a、public
    b、private
    c、static
    d、protected

23、you have a public class called myclass with the main method defined as follows public static void main(string parm[]){ system.out.println(parm[0]); } if you attempt to compile the class and run the program as follows java myclass hello what will happen?
    a、compile time error, main is not correctly defined
    b、run time error, main is not correctly defined
    c、compilation and output of java
    d、compilation and output of hello

24、which of the following are correct statements to create a lock so the longest-wait thread will obtain the lock first?()
    a、lock lock = new lock();
    b、lock lock = new reentrantlock();
    c、lock lock = new reentrantlock(true);
    d、lock lock = new reentrantlock(false);

25、which specifier essentially declares a variable a global variable?
    a、protected
    b、static
    c、final
    d、default

26、如何在condition对象实例上创建线程锁?()
    a、condition condition = lock.getcondition();
    b、condition condition = lock.newcondition();
    c、condition condition = lock.newcondition();
    d、condition condition = lock.getcondition();

27、which of the following statement prints smith\exam1\test.txt?
    a、system.out.println("smith\exam1\test.txt");
    b、system.out.println("smith\\exam1\\test.txt");
    c、system.out.println("smith\"exam1\"test.txt");
    d、system.out.println("smith"\exam1"\test.txt");

28、有如下代码: class a extends thread{ public void run{ for(int i=1;i<100;i ){system.out.println(i);} }} 能正确启动a中run方法的是()
    a、a.run();
    b、a a1=new a(); a1.run();
    c、a a1=new a(); a1.start();
    d、a a1=new a(); thread t=new thread(a); a.start();

29、which of the following is the correct expression of character 4?
    a、4
    b、"4"
    c、'4'
    d、'\0004'

30、程序如下: public class borley extends thread { public static void main(string[] argv) { borley b = new borley(); b.start(); } public void run() { system.out.println("running"); } } 下面描述正确的是()。
    a、通过编译和运行但是没有任何输出
    b、通过编译,运行后输出"running"
    c、编译出错,没有线程可供运行
    d、编译出错,没有权限使用thread

复习测验3

1、which of the following statements are true?()
    a、the wait(), notify(), and notifyall() methods must be invoked from a synchronized method or a synchronized block.
    b、when wait() is invoked, it pauses the thread and releases the lock on the object simultaneously. when the thread is restarted after being notified, the lock is automatically reacquired.
    c、the notify() method can wake only one waiting thread.
    d、an exception would occur if no thread is waiting on the object when the notify() method is invoked on the object.

2、which of the following statements are not true?
    a、a method in an interface must not have a body
    b、a class may extend one other class plus at most one interface
    c、a class may extends at most one other class plus implement many interfaces
    d、an class accesses an interface via the keyword implements

3、which of the following statements are not true
    a、a default constructor is provided automatically if no constructors are explicitly declared in the class
    b、at least one constructor must always be defined explicitly
    c、the default constructor is a no-arg constructor
    d、a default constructor always exist in class

4、which of the following declares an abstract method in an abstract java class?
    a、public abstract method();
    b、public abstract void method();
    c、public void abstract method();
    d、public abstract void method() {}

5、which of the following class definitions defines a legal abstract class?
    a、class a { abstract void unfinished() { } }
    b、class a { abstract void unfinished(); }
    c、abstract class a { abstract void unfinished(); }
    d、public class abstract a { abstract void unfinished(); }

6、which of the following are not true.
    a、a static method may be invoked before even a single instance of the class is constructed
    b、a static method cannot access non-static methods of the class
    c、abstract modifier can appear before a class or a method but not before a variable
    d、final modifier can appear before a class or a variable but not before a method

7、what will happen when you try compiling and running this code? public class ref{ public static void main(string argv[]){ ref r = new ref(); r.amethod(r); } public void amethod(ref r){ int i=99; multi(r); system.out.println(i); } public void multi(ref r){ r.i = r.i*2; }}
    a、error at compile time
    b、an output of 99
    c、an output of 198
    d、an error at runtime

8、what will happen when you compile and run the following code? public class scope{ private int i; public static void main(string argv[]){ scope s = new scope(); s.amethod(); }//end of main public static void amethod(){ system.out.println(i); }//end of amethod }//end of class
    a、a value of 0 will be printed out
    b、nothing will be printed out
    c、a compile time error
    d、a compile time error complaining of the scope of the variable i

9、what will happen when you attempt to compile and run the following code. public class pvf{ static boolean paddy; public static void main(string argv[]){ system.out.println(paddy); } }
    a、compile time error
    b、compilation and output of false
    c、compilation and output of true
    d、compilation and output of null

10、what will be the result of attempting to compile and run the following code? abstract class minebase { abstract void amethod(); static int i;}public class mine extends minebase { public static void main(string argv[]){ int[] ar=new int[5]; for(i=0;i < ar.length;i ) system.out.println(ar[i]); }}
    a、a sequence of 5 0's will be printed
    b、error: ar is used before it is initialized
    c、error mine must be declared abstract
    d、indexoutofboundes error

11、what modifier should you use on the members of a class so that they are not accessible to another class in a different package, but are accessible to any subclasses in any package?
    a、public
    b、private
    c、protected
    d、use the default modifier

12、what modifier should you use on a class so that a class in the same package can access it but a class in a different package cannot access it?
    a、public
    b、private
    c、protected
    d、use the default modifier

13、what is wrong in the following code? class tempclass { int i; public void tempclass(int j) { int i = j; } } public class c { public static void main(string[] args) { tempclass temp = new tempclass(2); } }
    a、the program has a compilation error because tempclass does not have a default constructor
    b、the program has a compilation error because tempclass does not have a constructor with an int argument
    c、the program compiles fine, but it does not run because class c is not public
    d、the program compiles and runs fine

14、what is the output of the following code: public class test { public static void main(string[] args) { object o1 = new object(); object o2 = new object(); system.out.print((o1 == o2) " " (o1.equals(o2))); } }
    a、false false
    b、true true
    c、false true
    d、true false

15、what gets displayed on the screen when the following program is compiled and run. select the one correct answer. protected class example { public static void main(string args[]) { string test = "abc"; test = test test; system.out.println(test); } }
    a、the class does not compile because the top level class cannot be protected
    b、the program prints "abc"
    c、the program prints "abcabc"
    d、the program does not compile because statement "test = test test" is illegal

16、variables that are shared by every instances of a class are __________.
    a、public variables
    b、private variables
    c、instance variables
    d、class variables

17、to make a variable defined in a class accessible only to methods defined in the classes in same package, which of the following keyword should be used. select the one correct answer
    a、by using the keyword private before the variable
    b、by using the keyword protected before the variable
    c、by using the keyword public before the variable
    d、the variable should not be preceded by any of the above mentioned keywords

18、test类中合法的构造函数是
    a、test() { }
    b、test() { }
    c、void test() { }
    d、private final test() { }

19、select the one most appropriate answer. a top level class without any modifier is accessible to
    a、any class
    b、any class within the same package
    c、any class within the same file
    d、any subclass of this class

20、given: class cardboard { short story = 200; cardboard go(cardboard cb) { cb = null; return cb; } public static void main(string[] args) { cardboard c1 = new cardboard(); cardboard c2 = new cardboard(); cardboard c3 = c1.go(c2); c1 = null; // do stuff } } when // dostuff is reached, how many objects are eligible for gc?
    a、0
    b、1
    c、2
    d、3

21、given: 5. class a { void m() { system.out.println("outer"); } } 6. 7. public class testinners { 8. public static void main(string[] args) { 9. new testinners().go(); 10. } 11. void go() { 12. new a().m(); 13. class a { void m() { system.out.println("inner"); } } 14. } 15. class a { void m() { system.out.println("middle"); } } 16. } what is the result?
    a、inner
    b、outer
    c、middle
    d、compilation fails

22、given: 3. public class tour { 4. public static void main(string[] args) { 5. cathedral c = new cathedral(); 6. // insert code here 7. s.go(); 8. } 9. } 10. class cathedral { 11. class sanctum { 12. void go() { system.out.println("spooky"); } 13. } 14. } which, inserted independently at line 6, compile and produce the output "spooky"?
    a、sanctum s = c.new sanctum();
    b、c.sanctum s = c.new sanctum();
    c、c.sanctum s = cathedral.new sanctum();
    d、cathedral.sanctum s = c.new sanctum();

23、given: 3. public class navel { 4. private int size = 7; 5. private static int length = 3; 6. public static void main(string[] args) { 7. new navel().go(); 8. } 9. void go() { 10. int size = 5; 11. system.out.println(new gazer().adder()); 12. } 13. class gazer { 14. int adder() { return size * length; } 15. } 16. } what is the result?
    a、15
    b、21
    c、an exception is thrown at runtime
    d、compilation fails due to multiple errors

24、given: 1. // insert code here 2. class stattest { 3. public static void main(string[] args) { 4. system.out.println(integer.max_value); 5. } 6. } which, inserted independently at line 1, compiles?
    a、import static java.lang;
    b、import static java.lang.integer;
    c、import static java.lang.integer.*;
    d、import static java.lang.integer.*_value;

25、given two files: 1. package pkga; 2. public class foo { 3. int a = 5; 4. protected int b = 6; 5. public int c = 7; 6. } 3. package pkgb; 4. import pkga.*; 5. public class baz { 6. public static void main(string[] args) { 7. foo f = new foo(); 8. system.out.print(" " f.a); 9. system.out.print(" " f.b); 10.system.out.print(" " f.c); 11. } 12. } what is the result?
    a、5 6 7
    b、5 followed by an exception
    c、compilation fails with an error on line 7
    d、compilation fails with an error on line 8 and line 9

26、given the following code public class sytch{ int x=2000; public static void main(string argv[]){ system.out.println("ms " argv[1] "please pay $" x); } } what will happen if you attempt to compile and run this code with the command line java sytch jones diggle
    a、compilation and output of ms diggle please pay $2000
    b、compile time error
    c、compilation and output of ms jones please pay $2000
    d、compilation but runtime error

27、given the declaration circle[] x = new circle[10], which of the following statement is most accurate?
    a、x contains an array of ten int values
    b、x contains an array of ten objects of the circle type
    c、x contains a reference to an array and each element in the array can hold a reference to a circle object
    d、x contains a reference to an array and each element in the array can hold a circle object

28、given the declaration circle x = new circle(), which of the following statement is most accurate.
    a、x contains an int value
    b、x contains an object of the circle type
    c、x contains a reference to a circle object
    d、you can assign an int value to x

29、assume java.util.date[] dates = new java.util.date[10], which of the following statements are true?
    a、dates is null
    b、dates[0] is null
    c、dates = new date() is fine, which creates a new date object and assigns to dates
    d、dates = new java.util.date[5] is wrong

30、given two reference variables t1 and t2, if t1.equals(t2) is true, t1 == t2 ____
    a、is always false
    b、is always true
    c、may be true or false
    d、i don't know

复习测验4

1、analyze the following code: public class test { public static void main(string args[]) { nclass nc = new nclass(); nc.t = nc.t ; } } class nclass { int t; private nclass() { } }
    a、the program has a compilation error because the nclass class has a private constructor
    b、the program does not compile because the parameter list of the main method is wrong
    c、the program compiles, but has a runtime error because t has no initial value
    d、the program compiles and runs fine

2、analyze the following code: public class test { private int t; public static void main(string[] args) { int x; system.out.println(t); } }
    a、the variable t is not initialized and therefore causes errors
    b、the variable t is private and therefore cannot be accessed in the main method
    c、t is non-static and it cannot be referenced in a static context in the main method
    d、the variable x is not initialized and therefore causes errors

3、analyze the following code: class circle { private double radius; public circle(double radius) { radius = radius; } }
    a、the program has a compilation error because it does not have a main method
    b、the program will compile, but you cannot create an object of circle with a specified radius. the object will always have radius 0
    c、the program has a compilation error because you cannot assign radius to radius
    d、the program does not compile because circle does not have a default constructor

4、analyze the following code and choose the best answer: public class foo { private int x; public static void main(string[] args) { foo foo = new foo(); system.out.println(foo.x); } }
    a、since x is private, it cannot be accessed from an object foo
    b、since x is defined in the class foo, it can be accessed by any method inside the class without using an object. you can write the code to access x without creating an object such as foo in this code
    c、since x is an instance variable, it cannot be directly used inside a main method. however, it can be accessed through an object such as foo in this code
    d、you cannot create a self-referenced object; that is, foo is created inside the class foo

5、a top level class may have only the following access modifier. select the one correct answer
    a、friendly
    b、private
    c、protected
    d、public

6、8、 给出下面的代码段 public class base{ int x, y; static int z; public base(int a,int b) { x=a; y=b; } } 以下代码错误的是?【 】
    a、base b=new base(); b.z=10;
    b、base b=new base(1,2); b.z=10;
    c、base.z=10;
    d、base b=new base(1,2); b.x=2;

7、6、 已知如下类说明 public class test { private float f = 1.0; int m = 12; static int n=1; public static void main(string arg[]) { test t = new test(); ____________________________. } } 在空格处如下哪个使用是错误的?【 】
    a、t.f
    b、this.m
    c、t.m
    d、n

8、下以下哪个类能正确编译?【 】
    a、class k{ abstract void b(){ } }
    b、abstract class k{ void b(){ } }
    c、abstract class k{ abstract void b(){}}
    d、abstract class k{ final abstract void b(); }

9、实现接口用哪个关键字【 】
    a、interface
    b、package
    c、implements
    d、extends

10、to prevent a class from being instantiated, ____________
    a、don't use any modifiers on the constructor
    b、use the public modifier on the constructor
    c、use the private modifier on the constructor
    d、use the static modifier on the constructor

11、public class base{ int x; static int z; public base() { z ;(1)} public static void main(string[] args){ int y; base b=new base(); system.out.print(base.z);(20) system.out.print(x);(3) system.out.print(y);(4) } } 会出错的语句是【 】
    a、(1)
    b、(2)
    c、(3)
    d、(4)

12、在java中,能实现多重继承效果的方式是( )
    a、内部类
    b、适配器
    c、接口
    d、同步

13、成员变量的属性有private、public、缺省、protected四种,若类a中有一个成员变量为m,类b为a同一个包的子类,类c为a的不同包的子类,则变量m定义为( )属性,在b中能访问到m,但是在c中却访问不到。【 】
    a、private
    b、public
    c、缺省
    d、protected

14、编译并运行以下程序,以下描述哪个选项是正确的( ) 1: class x{ 2: protected string tostring(){ 3: return super.tostring();} 4: }
    a、编译通过运行无异常
    b、编译通过但运行时出错
    c、行2出错,不能成功编译
    d、不能成功编译,行3出错

15、which statements are most accurate regarding the following classes? class a { private int i; protected int j; } class b extends a { private int k; protected int m; }
    a、an object of b contains data fields i, j, k, m
    b、an object of b contains data fields j, k, m
    c、an object of b contains data fields j, m
    d、an object of b contains data fields k, m

16、which of the following statements are true?
    a、methods cannot be overriden to be more private
    b、static methods cannot be overloaded
    c、private methods cannot be overloaded
    d、an overloaded method cannot throw exceptions not checked in the base class

17、which of the following statements are true?
    a、a method cannot be overloaded to be less public in a child class
    b、to be overridden a method only needs the same name and parameter types
    c、to be overridden a method must have the same name, parameter and return types
    d、an overridden method must have the same name, parameter names and parameter types

18、which of the following statements are true?
    a、static methods cannot be overriden to be non static
    b、static methods cannot be declared as private
    c、private methods cannot be overloaded
    d、an overloaded method cannot throw exceptions not checked in the base class

19、which of the following statements are true
    a、constructors cannot be overloaded
    b、constructors cannot be overridden
    c、a constructor can return a primitive or an object reference
    d、constructor code executes from the current class up the hierarchy to the ancestor class

20、which of the following classes cannot be extended?
    a、class a { }
    b、class a { private a();}
    c、final class a { }
    d、class a { protected a();}

21、which is true?
    a、"x extends y" is correct if and only if x is a class and y is an interface
    b、"x extends y" is correct if and only if x is an interface and y is a class
    c、"x extends y" is correct if x and y are either both classes or both interfaces
    d、"x extends y" is correct for all combinations of x and y being classes and/or interfaces

22、what will happen when you attempt to compile and run this code? abstract class base{ abstract public void myfunc(); public void another(){ system.out.println("another method"); }} public class abs extends base{ public static void main(string argv[]){ abs a = new abs(); a.amethod(); } public void myfunc(){ system.out.println("my func"); } public void amethod(){ myfunc(); }}
    a、the code will compile and run, printing out the words "my func"
    b、the compiler will complain that the base class has non abstract methods
    c、the code will compile but complain at run time that the base class has non abstract methods
    d、the compiler will complain that the method myfunc in the base class has no body, nobody at all to looove it

23、what will happen when you attempt to compile and run the following code? class base{ base(){ system.out.println("base"); } } public class checket extends base{ public static void main(string argv[]){ checket c = new checket(); super(); } checket(){ system.out.println("checket"); } }
    a、compile time error
    b、checket followed by base
    c、base followed by checket
    d、runtime error

24、what will happen when you attempt to compile and run the following code class base{ public void base(){ system.out.println("base"); } } public class in extends base{ public static void main(string argv[]){ in i=new in(); } }
    a、compile time error base is a keyword
    b、compilation and no output at runtime
    c、output of base
    d、runtime error base has no valid constructor

25、what will happen when you attempt to compile and run the following code class base{ private void amethod(int ibase){ system.out.println("base.amethod"); }}class over extends base{ public static void main(string argv[]){ over o = new over(); int ibase=0; o.amethod(ibase); } public void amethod(int iover){ system.out.println("over.amethod"); }}
    a、compile time error complaining that base.amethod is private
    b、runtime error complaining that base.amethod is private
    c、output of "base.amethod"
    d、output of "over.amethod"

26、what will happen when you attempt to compile and run the following class? class base{ base(int i){ system.out.println("base"); } } class severn extends base{ public static void main(string argv[]){ severn s = new severn(); } void severn(){ system.out.println("severn"); } }
    a、compilation and output of the string "severn" at runtime
    b、compile time error
    c、compilation and no output at runtime
    d、compilation and output of the string "base"

27、what is the output of running class c? class a { public a() { system.out.println( "the default constructor of a is invoked"); } } class b extends a { public b() { system.out.println( "the default constructor of b is invoked"); } } public class c { public static void main(string[] args) { b b = new b(); } }
    a、nothing displayed
    b、"the default constructor of b is invoked"
    c、"the default constructor of a is invoked""the default constructor of b is invoked"
    d、"the default constructor of b is invoked""the default constructor of a is invoked"

28、suppose you create a class cylinder to be a subclass of circle. analyze the following code: class cylinder extends circle { double length; cylinder(double radius) { circle(radius); } }
    a、the program compiles fine, but you cannot create an instance of cylinder because the constructor does not specify the length of the cylinder
    b、the program has a compile error because you attempted to invoke the circle class's constructor illegally
    c、the program compiles fine, but it has a runtime error because of invoking the circle class's constructor illegally
    d、the program compiles and run fine

29、object-oriented programming allows you to derive new classes from existing classes. this is called ________
    a、encapsulation
    b、inheritance
    c、abstraction
    d、generalization

30、下面说法正确的是?
    a、一个子类可以有多个父类,一个父类也可以有多个子类
    b、一个子类可以有多个父类,但一个父类只可以有一个子类
    c、一个子类可以有一个父类,但一个父类可以有多个子类
    d、上述说法都不对

复习测验5

1、inheritance means _______
    a、that data fields should be declared private
    b、that a class can extend another class
    c、that a variable of supertype can refer to a subtype object
    d、that a class can contain another class

2、given: public abstract interface frobnicate { public void twiddle(string s); } which is a correct class?
    a、public abstract class frob implements frobnicate { public abstract void twiddle(string s) { } }
    b、public abstract class frob implements frobnicate { }
    c、public class frob extends frobnicate { public void twiddle(integer i) { } }
    d、public class frob implements frobnicate { public void twiddle(integer i) { } }

3、given: class clidder { private final void flipper() { system.out.println("clidder"); } } public class clidlet extends clidder { public final void flipper() { system.out.println("clidlet"); } public static void main(string [] args) { new clidlet().flipper(); } } what is the result?
    a、clidlet
    b、clidder
    c、clidder clidlet
    d、clidlet clidder

4、given: 3. class building { 4. building() { system.out.print("b "); } 5. building(string name) { 6. this(); system.out.print("bn " name); 7. } 8. } 9. public class house extends building { 10. house() { system.out.print("h "); } 11. house(string name) { 12. this(); system.out.print("hn " name); 13. } 14. public static void main(string[] args) { new house("x "); } 15. } what is the result?
    a、h hn x
    b、hn x h
    c、b h hn x
    d、b hn x h

5、given: 3. class alpha { 4. static string s = " "; 5. protected alpha() { s = "alpha "; } 6. } 7. class subalpha extends alpha { 8. private subalpha() { s = "sub "; } 9. } 10. public class subsubalpha extends alpha { 11. private subsubalpha() { s = "subsub "; } 12. public static void main(string[] args) { 13. new subsubalpha(); 14. system.out.println(s); 15. } 16. } what is the result?
    a、subsub
    b、sub subsub
    c、alpha subsub
    d、alpha sub subsub

6、given: 1. public class electronic implements device 2.{ public void doit() { } } 3. abstract class phone1 extends electronic { } 5. abstract class phone2 extends electronic 6.{ public void doit(int x) { } } 7. class phone3 extends electronic implements device 8.{ public void dostuff() { } } 9. interface device { public void doit(); } what is the result?
    a、compilation succeeds
    b、compilation fails with an error on line 1
    c、compilation fails with an error on line 3
    d、compilation fails with an error on line 5

7、given: 1. public abstract class shape { 2. private int x; 3. private int y; 4. public abstract void draw(); 5. public void setanchor(int x, int y) { 6. this.x = x; 7. this.y = y; 8. } 9. } which class use the shape class correctly?
    a、public class circle implements shape {private int radius;}
    b、public abstract class circle extends shape { private int radius; }
    c、public class circle extends shape { private int radius; public void draw(); }
    d、public abstract class circle implements shape { private int radius; public void draw(); }

8、given the following code how could you invoke the base constructor that will print out the string "base constructor"; class base{ base(int i){ system.out.println("base constructor"); } base(){ } } public class sup extends base{ public static void main(string argv[]){ sup s= new sup(); //one } sup() { //two } public void derived() { //three }}
    a、on the line after //one put base(10);
    b、on the line after //one put super(10);
    c、on the line after //two put super(10);
    d、on the line after //three put super(10);

9、analyze the following code: public class test { public static void main(string[] args) { b b = new b(); b.m(5); system.out.println("i is " b.i); } } class a { int i; public void m(int i) { this.i = i; } } class b extends a { public void m(string s) { } }
    a、the program has a compilation error, because m is overridden with a different signature in b
    b、the program has a compilation error, because b.m(5) cannot be invoked since the method m(int) is hidden in b
    c、the program has a runtime error on b.i, because i is not accessible from b
    d、the method m is not overridden in b. b inherits the method m from a and defines an overloaded method m in b

10、一个java类最多可以继承的父类个数为【 】个
    a、1
    b、2
    c、3
    d、多个

11、给出下面的代码段 class b { int n=1; void disp(){ system.out.print (n); } } class c extends b { int n=2; void disp(){ super.disp(); system.out.print(super.n); system.out.print(n); } public static void main(string[] args) { (new c()).disp(); } }; 运行结果哪项是正确的?【 】
    a、112
    b、222
    c、111
    d、221

12、在 java 中,所有类的根类是( )
    a、java.lang.object
    b、java.lang.class
    c、java.applet.applet
    d、java.awt.frame

13、以下哪项是接口的正确定义?
    a、interface b { void print() { } ;}
    b、abstract interface b { void print() ;}
    c、abstract interface b extends a1,a2 //a1、a2为已定义的接口 { abstract void print(){ };}
    d、interface b { void print();}

14、下面是people和child类的定义和构造方法,每个构造方法都输出编号。在执行new child("mike")的时候都有哪些构造方法被顺序调用?请选择输出结果 ( ) class people { string name; public people() { system.out.print(1); } public people(string name) { system.out.print(2); this.name = name; } } class child extends people { people father; public child(string name) { system.out.print(3); this.name = name; father = new people(name ":f"); } public child(){ system.out.print(4); } }
    a、312
    b、32
    c、13
    d、132

15、出下面的代码__ _______ __。 class person{ string name,department; public void printvalue(){ system.out.println(“name is” name); } } public class teacher extends person{ int salary; public void printvalue(){ _______________________ system.out.println(“salary is” salary); } } 下面的哪个表达式可以加入到teacher类的printvalue()方法中。______
    a、printvalue();
    b、this.printvalue();
    c、person.printvalue();
    d、super.printvalue();

16、8、 有如下代码: //a.java class a { int x; public a(int x){ this.x=x;} } //b.java class b extends a{ string name; public b(string name){ x=10; this.name=name; } public static void main(string[] args){ b b=new b("tom"); system.out.println(b.name b.x); } } 以下说法正确的是【 】
    a、编译b通过,运行b,输出:tom10;
    b、编译b通过,运行b失败,因为b.name b.x中字符串不能与整型相加
    c、编译b失败,因为b.name b.x中字符串不能与整型相加
    d、编译b失败,因为a中没有无参构造函数

17、analyze the following code.the correct answer is () // test.java: define threads using the thread class import java.util.*; public class test { private stack stack = new stack(); private int i = 0; /** main method */ public static void main(string[] args) { new test(); } public test() { // start threads new producer().start(); new consumer().start(); } class producer extends thread { public void run() { while (true) { system.out.println("producer: put " i); stack.push(new integer(i )); synchronized (stack) { notifyall(); } } } } class consumer extends thread { public void run() { while (true) { synchronized (stack) { try { while (stack.isempty()) stack.wait(); system.out.println("consumer: get " stack.pop()); } catch (interruptedexception ex) { ex.printstacktrace(); } } } } } }
    a、the program creates two threads: one to add data to the stack and the other to get data from the stack.
    b、the program has a compilation error on the notifyall() method in the producer class because it is not invoked from the stack object.
    c、the program will throw an exception because the notifyall() method in the producer class is not invoked from the stack object.
    d、the program has a logic error because the lock obtained by the synchronized block for notifyall in the producer class is stack and it should be this (i.e., synchronized (this) { notifyall(); }).

18、看下面一段程序:   class aclass{    void go(){     system.out.println("aclass");    }   }   public class bclass extends aclass{    void go{     system.out.println("bclass");    }   public static void main(string args[]){    aclass a=new aclass();    aclass a1=new bclass();   a.go();   a1.go();   } 以上程序运行结果是:
    a、aclass aclass
    b、aclass bclass
    c、bclass aclass
    d、bclass bclass

19、假设类a是类b的父类,下列声明对象x的语句中不正确的是
    a、a x=new a();
    b、a x=new b();
    c、b x=new b();
    d、b x=new a();

20、what is the output of the following code? public class test { public static void main(string[] args) { new person().printperson(); new student().printperson(); } } class student extends person { public string getinfo() { return "student"; } } class person { public string getinfo() { return "person"; } public void printperson() { system.out.println(getinfo()); } }
    a、person person
    b、person student
    c、stduent student
    d、student person

21、polymorphism means ___________
    a、that data fields should be declared private
    b、that a class can extend another class
    c、that a variable of supertype can refer to a subtype object
    d、that a class can contain another class

22、in implementing two classes employee and manager, such that each manager is an employee, what should be the relationship between these classes. select the one correct answer
    a、employee should be the base class of manager class
    b、manager should be the base class of employee class
    c、manager class should include the employee class as a data member
    d、employee class should include manager class as a data member

23、given: 1. class foo { 2. public int a = 3; 3. public void addfive() { a = 5; system.out.print("f "); } 4. } 5. class bar extends foo { 6. public int a = 8; 7. public void addfive() { this.a = 5; system.out.print("b " ); } 8. } invoked with: foo f = new bar(); f.addfive(); system.out.println(f.a); what is the result?
    a、b 3
    b、b 8
    c、b 13
    d、f 3

24、given the following code class base {} class agg extends base{ public string getfields(){ string name = "agg"; return name; } } public class avf{ public static void main(string argv[]){ base a = new agg(); //here } } what code placed after the comment //here will result in calling the getfields method resulting in the output of the string "agg"?
    a、system.out.println(a.getfields());
    b、system.out.println(a.name);
    c、system.out.println((base) a.getfields());
    d、system.out.println( ((agg) a).getfields());

25、a派生出子类b,b派生出子类c,并且在java源代码中有如下声明: 1. a a0=new a(); 2. a a1 =new b(); 3. a a2=new c(); 问以下哪个说法是正确的?
    a、只有第1行能通过编译
    b、第1、2行能通过编译,但第3行编译出错
    c、第1、2、3行能通过编译,但第2、3行运行时出错
    d、第1行、第2行和第3行的声明都是正确的

26、使用下列哪个布局管理器时,当frame的大小变化时,在frame上的按钮的位置会发生变化?
    a、borderlayout
    b、flowlayout
    c、cardlayout
    d、gridlayout

27、a button is positioned in a frame. only height of the button is affected by the frame while the width is not. which layout manager should be used?
    a、flowlayout
    b、cardlayout
    c、north and south of borderlayout
    d、east and west of borderlayout

28、given a list using a proportional pitch font and constructed like this: list l=new list(5,true); which statement is true?
    a、the displayed item exactly five lines unless otherwise constrained
    b、the displayed item is five lines init, but can displayed more than five item by scroll
    c、the maximum number of item in a list will be five.
    d、the list is multiple mode

29、what is the return value of the method in the event listener interface?
    a、int
    b、string
    c、void
    d、object

30、which statement is true?
    a、a flow layout can be used to position a component that should resize horizontally when the container is resized.
    b、a grid layout can be used to position a component tat should maintain a constant size even when the container is resized.
    c、a border layout can be used to position component that should maintain a constant size even when the container is resized.
    d、the grid bag layout can be used to give a grid-like layout which differs from the normal grid in that individual rows and columns can have unique sizes.

复习测验6

1、given an actionevent,which method allows you to identify the affected component?
    a、public class getclass()
    b、public object getsource()
    c、public component getsource()
    d、public component gettarget()

2、which type of event indicates a key pressed on a java.awt.component?
    a、keyevent
    b、keydownevent
    c、keypressevent
    d、keytypedevent

3、which statement is true?
    a、a grid bag layout can position components such that they span multiple rows and/or columns.
    b、the“north”region of a border layout is the proper place to locate a menubar component in a frame.
    c、components in a grid bag layout may either resize with their cell,or remain centered in that cell at their preferred size.
    d、a border layout can be used to position a component that should maintain a constant size even when the container is resized.

4、clicking the closing button on the upper-right corner of a frame generates a(n) __________ event.
    a、itemevent
    b、windowevent
    c、mousemotionevent
    d、componentevent

5、用来处理监听器的组件是_________________.
    a、the source object
    b、the listener object
    c、the adapter object
    d、the adapter object

6、the interface __________ should be implemented to listen for a button action event.
    a、mouselistener
    b、actionlistener
    c、focuslistener
    d、windowlistener

7、每一个事件对象都包含________________方法。
    a、getsource()
    b、getactioncommand()
    c、gettimestamp()
    d、getwhen()

8、为了监听鼠标移动事件,监听器必须实现_________接口,或者继承____________类。
    a、mouselistener/mouseadapter
    b、mousemotionlistener/mousemotionadapter
    c、windowlistener/windowadapter
    d、componentlistener/componentadapter

9、为了获得鼠标事件evt中鼠标点击位置的x坐标,可以使用___________方法。
    a、evt.getx()
    b、evt.getpoint().x
    c、either a or b
    d、neither a nor b

10、to listen to keyboard actions, the listener must implement the __________ interface or extend the _________ class.
    a、mouselistener/mouseadapter
    b、keylistener/keyadapter
    c、windowlistener/windowadapter
    d、componentlistener/componentadapter

11、the getkeycode() method of the keyevent returns __________.
    a、a character
    b、the ascii code of the character
    c、the unicode code of the character
    d、none of the above.

12、which component cannot be added to a container?
    a、jpanel
    b、jbutton
    c、jframe
    d、jcomponent

13、what is best to describe the relationship between jcomponent and jbutton?
    a、association
    b、aggregation
    c、composition
    d、inheritance

14、what is best to describe the relationship between component and font?
    a、association
    b、aggregation
    c、composition
    d、inheritance

15、下面三个表达式中,正确的是 ___________. 1. frame.setlocationrelativeto(null); 2. frame.setsize(100, 200); 3. frame.setvisible(true);
    a、1 2 3
    b、1 3 2
    c、2 1 3
    d、3 2 1

16、how many frames are displayed? import javax.swing.*; public class test extends jframe { public static void main(string[] args) { jframe f1 = new test(); jframe f2 = new test(); jframe f3 = new test(); f1.setvisible(true); f2.setvisible(true); f3.setvisible(true); } }
    a、1
    b、2
    c、3
    d、0

17、which of the following is not an advantage of using methods?
    a、using methods makes program run faster
    b、using methods makes reusing code easier
    c、using methods makes programs easier to read
    d、using methods hides detailed implementation from the clients

18、which of the following can be placed in the blank line in the following code? public class test { private static int id; public static void m1() { _____.id = 45; } }
    a、this
    b、test
    c、test
    d、super

19、which of the following can be placed in the blank line in the following code? public class test { private int id; public void m1() { _____.id = 45; } }
    a、this
    b、test
    c、test
    d、super

20、which access specifier allows class members to be accessed by any class in its own package?
    a、protected
    b、public
    c、private
    d、default

21、what is the value of b after execution? int x, b=0; for(x = 0; x <= 5; x){ if (x == 2) break; b; }
    a、0
    b、1
    c、2
    d、3

22、what is the value of b after execution? int x, b=0; for(x = 0; x <= 5; x){ if (x == 2) continue; b; }
    a、5
    b、4
    c、3
    d、2

23、what is the printout of the following code: double x = 5.5; int y = (int)x; system.out.println("x is " x " and y is " y);
    a、x is 5 and y is 6
    b、x is 6.0 and y is 6.0
    c、x is 6 and y is 6
    d、x is 5.5 and y is 5

24、to improve readability and maintainability, you should declare _________ instead of using literal values such as 3.14159.
    a、variables
    b、methods
    c、constants
    d、classes

25、to declare a constant max_length inside a method with value 99.98, you write
    a、final max_length = 99.98;
    b、final float max_length = 99.98;
    c、double max_length = 99.98;
    d、final double max_length = 99.98;

26、to add number to sum, you write
    a、number = sum;
    b、number = sum number;
    c、sum = number sum;
    d、sum = number;

27、the default value for data field of a boolean type, numeric type, object type is ___________, respectively
    a、true, 1, null
    b、false, 0, null
    c、true, 0, null
    d、true, 1, null

28、test.java程序代码如下: 1) public class test{ 2) public static void main(string[] args){ 3) system.out.println(args[1]); 4) } 5) } 以上程序编译后用java test 2 3 4 5运行的输出结果是什么? ( )
    a、2
    b、3
    c、4
    d、5

29、system.out.println("5" 2);的输出结果应该是
    a、52
    b、7
    c、2
    d、编译错

30、suppose x is a char variable with a value 'b'. what is the printout of the statement system.out.println( x)?
    a、a
    b、b
    c、c
    d、d

复习测验7

1、suppose x is a char variable with a value 'b'. what is the printout of the statement system.out.println( x)?
    a、a
    b、b
    c、c
    d、d

2、main()方法的返回类型是:
    a、boolean
    b、void
    c、string
    d、static

3、java的字符类型采用的是unicode编码方案,每个unicode码占用( )个比特位
    a、8
    b、16
    c、32
    d、64

4、in the program segment below, which line prints? int x=3, y=5; if (x < y) system.out.println("x= " x); system.out.println("y= " y);
    a、the first one
    b、the second one
    c、both
    d、neither

5、how many times will the print statement execute? for (x=0; x<=5; x) { system.out.println("x= " x); --x;}
    a、3
    b、4
    c、5
    d、an infinite number of times

6、given: 1. public void go() { 2. string o = ""; 3. z: 4. for(int x = 0; x < 3; x ) { 5. for(int y = 0; y < 2; y ) { 6. if(x==1) break; 7. if(x==2 && y==1) break z; 8. o = o x y; 9. } 10. } 11. system.out.println(o); 12. } what is the result when the go() method is invoked?
    a、00
    b、0001
    c、000120
    d、00012021

7、given: 1. public class teststring1 { 2. public static void main(string[] args) { 3. string str = "420"; 4. str = 42; 5. system.out.print(str); 6. } 7. } what is the output?
    a、42
    b、420
    c、462
    d、42042

8、given: 1. public class test { 2. public static void main(string [] args) { 3. int x = 5; 4. boolean b1 = true; 5. boolean b2 = false; 6. 7. if ((x == 4) && !b2 ) 8. system.out.print("1 "); 9. system.out.print("2 "); 10. if ((b2 = true) && b1 ) 11. system.out.print("3 "); 12. } 13. } what is the result?
    a、2
    b、3
    c、1 2
    d、2 3

9、analyze the following code: public class test { public static void main(string[] args) { double radius; final double pi= 3.15169; double area = radius * radius * pi; system.out.println("area is " area); } }
    a、the program has compile errors because the variable radius is not initialized
    b、the program has a compile error because a constant pi is defined inside a method
    c、the program has no compile errors but will get a runtime error because radius is not initialized
    d、the program compiles and runs fine

10、an object is an instance of a __________.
    a、program
    b、class
    c、method
    d、data

11、a variable that is declared inside a method is called ________ variable
    a、a static
    b、an instance
    c、a local
    d、a global

12、__________ represents an entity in the real world that can be distinctly identified.
    a、a class
    b、an object
    c、a method
    d、a data field

13、________ is invoked to create an object
    a、a constructor
    b、the main method
    c、a method with a return type
    d、a method with the void return type

14、(double)(5/2)的值为?
    a、2
    b、2.0
    c、2.5
    d、3

15、to assign a value 1 to variable x, you write
    a、1 = x;
    b、x = 1;
    c、x := 1;
    d、x == 1;

16、45 / 4的值为?
    a、10
    b、11
    c、11.25
    d、12

17、在调用方法时,若要使方法改变实参的值,可以
    a、用基本数据类型作为参数
    b、用对象作为参数
    c、a和b都对
    d、a和b都不对

18、下述哪一组方法,是一个类中方法重载的正确写法? ( )
    a、int addvalue( int a, int b ){return a b;} float addvalue ( float a, float b) {return a b;}
    b、int addvalue (int a, int b ){value=a b;} float addvalue ( int a, int b) {return (float)(a b);}
    c、int addvalue( int a, int b ){return a 1;} int addvalue ( int b) {return b;}
    d、int addvalue( int a, int b ) {return a b;} int addvalue ( int x, int y ) {return x y;}

19、下述哪个说法是不正确的?( )
    a、局部变量在使用之前无需初始化,因为有该变量类型的默认值
    b、类成员变量由系统自动进行初始化,也无需初始化
    c、参数的作用域就是所在的方法
    d、for语句中定义的变量,当for语句执行完时,该变量就消亡了

20、下面代码中,空白处应填 ______________. public class test { public static void main(string[] args) { system.out.print("the grade is "); printgrade(78.5); system.out.print("the grade is "); printgrade(59.5); } public static __________ printgrade(double score) { if (score >= 90.0) { system.out.println('a'); } else if (score >= 80.0) { system.out.println('b'); } else if (score >= 70.0) { system.out.println('c'); } else if (score >= 60.0) { system.out.println('d'); } else { system.out.println('f'); } } }
    a、int
    b、string
    c、void
    d、char

21、下列方法头中哪一个不与其他方法形成重载(overload)关系?
    a、void mmm()
    b、void mmm(int i)
    c、void mmm(string s)
    d、int mm()

22、若在某一个类定义中定义有如下的方法:abstract void performdial( );该方法属于
    a、接口方法
    b、最终方法
    c、抽象方法
    d、空方法

23、下面哪个函数是public void amethod(){...}的重载函数?
    a、void amethod( ){...}
    b、public int amethod(){...}
    c、public void amethod ( ){...}
    d、public int amethod ( int m){...}

24、假设a类有如下定义,设a是a类的一个实例,下列语句调用哪个是错误的? class a { int i; static string s; void method1() { } static void method2() { } }
    a、system.out.println(a.i);
    b、a.method1();
    c、a.method1();
    d、a.method2();

25、you should add the static keyword in the place of ? in line ________ in the following code: 1 public class test { 2 private int age; 3 4 public ? int square(int n) { 5 return n * n; 6 } 7 8 public ? int getage() {return age; 9} 10}
    a、in line 4
    b、in line 8
    c、in both line 4 and line 8
    d、none

26、which of the following should be defined as a void method?
    a、write a method that prints integers from 1 to 100
    b、write a method that returns a random integer from 1 to 100
    c、write a method that checks whether current second is an integer from 1 to 100
    d、write a method that converts an uppercase letter to lowercase

27、which of the following are legal declaration and definition of a method
    a、void method() {};
    b、void method(void) {};
    c、method() {};
    d、method(void) {};

28、which method names follow the javabeans standard?
    a、addsize
    b、getcust
    c、deleterep
    d、putdimensions

29、when you invoke a method with a parameter, the value of the argument is passed to the parameter. this is referred to as _______
    a、method invocation
    b、pass by value
    c、pass by reference
    d、pass by name

30、when invoking a method with an object argument, ___________ is passed
    a、the contents of the object
    b、a copy of the object
    c、the reference of the object
    d、the object is copied, then the reference of the copied object

复习测验8

1、what is the value of times displayed? public class test { public static void main(string[] args) { count mycount = new count(); int times = 0; for (int i=0; i<100; i ) increment(mycount, times); system.out.println("times = " times); } public static void increment(count c, int times) { c.count ; times ; } } class count { int count; count(int c) { count = c; } count() { count = 1; } }
    a、101
    b、100
    c、1
    d、0

2、what is the value of mycount.count displayed? public class test { public static void main(string[] args) { count mycount = new count(); int times = 0; for (int i=0; i<100; i ) increment(mycount, times); system.out.println("mycount.count = " mycount.count); } public static void increment(count c, int times) { c.count ; times ; } } class count { int count; count(int c) { count = c; } count() { count = 1; } }
    a、101
    b、100
    c、99
    d、98

3、what is the printout of the second println statement in the main method? public class foo { int i; static int s; public static void main(string[] args) { foo f1 = new foo(); system.out.println("f1.i is " f1.i " f1.s is " f1.s); foo f2 = new foo(); system.out.println("f2.i is " f2.i " f2.s is " f2.s); } public foo() { i ; s ; } }
    a、f2.i is 1 f2.s is 1
    b、f2.i is 1 f2.s is 2
    c、f2.i is 2 f2.s is 2
    d、f2.i is 2 f2.s is 1

4、一个字节包含 ________ 位
    a、4
    b、8
    c、12
    d、16

5、which of the following statements is correct?
    a、every line in a program must end with a semicolon
    b、every statement in a program must end with a semicolon
    c、every comment line must end with a semicolon
    d、every method must end with a semicolon

6、java字节码文件的后缀是
    a、.java
    b、.obj
    c、.class
    d、.exe

7、java ___________ can run from a web browser
    a、applications
    b、applets
    c、servlets
    d、micro edition programs

8、every statement in java ends with ____
    a、a semicolon (;)
    b、a comma (,)
    c、a period (.)
    d、an asterisk (*)

9、computer can execute the code in ____________.
    a、assembly language
    b、high-level language
    c、machine language
    d、none of the above

10、___________ translates high-level language program into machine language program
    a、an assembler
    b、a compiler
    c、cpu
    d、the operating system

11、属于解释性程序是________
    a、java
    b、c
    c、c
    d、vb

12、which jdk command is correct to run a java application in bytecode.class?
    a、java bytecode
    b、java bytecode.class
    c、javac bytecode.java
    d、javac bytecode

13、suppose you define a java class as follows: public class test { } in order to compile this program, the source code should be stored in a file named
    a、test.java
    b、any name with extension .java
    c、test.class
    d、test.java

14、suppose you define a java class as follows: class test { } in order to compile this program, the source code should be stored in a file named
    a、test.java
    b、any name with extension .java
    c、test.class
    d、test.java

15、main函数声明正确的是
    a、public static void main(string[] args)
    b、public static void main(string[] args)
    c、public static void main(string[] args)
    d、public static main(string args[])

16、jdk是( )
    a、一种全新的程序语言
    b、一种程序开发辅助工具
    c、一种由java写成的,并支持java applet的浏览器
    d、一种游戏软件

17、jdk命令编译test.java,正确的是?
    a、java test
    b、java test.java
    c、javac test.java
    d、javac test

18、_________ is a software that interprets java bytecode
    a、java virtual machine
    b、java compiler
    c、java debugger
    d、java api

19、________ is architecture-neutral
    a、vb
    b、c
    c、c
    d、java

20、________ is a technical definition of the language that includes the syntax and semantics of the java programming language
    a、java language specification
    b、java api
    c、java jdk
    d、java ide

21、________ provides an integrated development environment (ide) for rapidly developing java programs. editing, compiling, building, debugging, and online help are integrated in one graphical user interface
    a、java language specification
    b、java api
    c、java jdk
    d、java ide

22、1、 阅读下面程序 public class test2 _______{ public static void main(string[] args){ thread t=new test2(); t.start(); } public void run(){ system.out.println(“how are you.); } } 在程序下划线处填入正确选项是()
    a、implements thread
    b、extemds runnable
    c、implements runnable
    d、extends thead

23、java程序的执行过程中用到一套jdk工具,其中java.exe是指( )
    a、java文档生成器
    b、java解释器
    c、java编译器
    d、java类分解器

24、java语言具有许多优点和特点,哪个反映了java程序并行机制的特点?(
    a、安全性
    b、多线性
    c、跨平台
    d、可移植

25、下列关于java语言的特点,描述错误的是( )
    a、java是跨平台的编程语言
    b、java支持分布式计算
    c、java是面向过程的编程语言
    d、java支持多线程

26、在 java 中,由java编译器自动导入,而无需在程序中用import导入的包是( )
    a、java.applet
    b、java.awt
    c、java.util
    d、java.lang

27、运行下段代码后,z的结果为?? int a = 1, z=0; do { z; } while(a < 0)
    a、0
    b、1
    c、2
    d、3

28、运行下段代码后,x的结果为? int x = 3; int y = 2; x *= y 1;
    a、6
    b、7
    c、8
    d、9

29、有如下程序段: int total = 0; for ( int i = 0; i < 4; i ){ if ( i == 1) continue; if ( i == 2) break; total = i; } 则执行完该程序段后total的值为:
    a、0
    b、1
    c、3
    d、6

30、有关类的说法正确的是? ( )
    a、类具有封装性,所以类的数据是不能被访问的
    b、类具有封装性,但可以通过类的公共接口访问类中的数据
    c、声明一个类时,必须用public修饰符
    d、每个类中,必须有main方法,否则程序无法运行

复习测验9

1、以下关于构造函数的描述错误的是
    a、构造函数的返回类型只能是void型
    b、构造函数是类的一种特殊函数,它的方法名必须与类名相同
    c、构造函数的主要作用是完成对类的对象的初始化工作
    d、一般在创建新对象时,系统会自动调用构造函数

2、下述概念中不属于面向对象方法的是
    a、对象、消息
    b、继承、多态
    c、类、封装
    d、过程调用

3、下面的选项中,哪一项不属于“汽车类”的行为
    a、启动
    b、刹车
    c、减速
    d、速度

4、下列说法中,不正确的是( )
    a、一个java源程序经过编译后,得到的文件的扩展名一定是.class
    b、一个java源程序编译通过后,得到的结果文件数也只有一个
    c、一个java源程序只能有一个public class类定义,且源文件的名字与public class的类名相同,扩展名必须是.java
    d、一个java源程序可以包含多个class类

5、下列说法正确的有( )
    a、class中的constructor不可省略
    b、constructor必须与class同名,但方法不能与class同名
    c、constructor在一个对象被new时执行
    d、一个class只能定义一个constructor

6、analyze the following code. import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class test extends a { public static void main(string[] args) { a frame = new test(); frame.setsize(200, 100); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setvisible(true); } jbutton jbtok = new jbutton("ok"); public test() { getcontentpane().add(jbtok); jbtok.addactionlistener(this); } public void actionperformed(actionevent e) { super.actionperformed(e); if (e.getsource() == jbtok) system.out.println("ok button is clicked"); } } class a extends jframe implements actionlistener { jbutton jbtcancel = new jbutton("cancel"); public a() { getcontentpane().setlayout(new flowlayout()); getcontentpane().add(jbtcancel); jbtcancel.addactionlistener(this); } public void actionperformed(actionevent e) { if (e.getsource() == jbtcancel) system.out.println("cancel button is clicked"); } }
    a、the program displays cancel button on the left of the ok button.
    b、when you click the ok button the message "ok button is clicked" is displayed.
    c、when you click the cancel button the message "cancel button is clicked" is displayed.
    d、if the super.actionperformed(e) statement in the actionperformed method in the test class is omitted, no message is displayed if you click the cancel button.

<< 上一篇下一篇 >>

备案号: 买球平台网址的版权所有 买球平台网址 copyright © 2012-2023 青果答案 all rights reserved. sitemap