java thread inner class example,Java经典模拟题(onlyfortrainning)

Java经典模拟题(onlyfortrainning)

来源:考试大    [ 2006-03-10 17:31:38 ]    责任编辑:qinqin

40. Which correctly create an array of five empty Strings?

A.String a[] = new String[5];

for (int i=0;i<5;a[i++]=””);

B.String a []={“”,””,””,””,””};

C.String a[5];

D.String [5] a;

E.String [] a = new String[5];

for (int i = 0 ;i<5;a[i++] = null);

41. Which cannot be added to a Container?

A. an AppletB. a ComponentC. a ContainerD. a MenuComponent

E. a panel

42. Which is the return value of Event listener’s method?

A. StringB. AWTEventC. voidD. int

43. If we implements MouseListener, which is corrected argument of its method? (short answer)

44. Use the operator “>;>;” and “>;>;>;”. Which statement is true?

A.1010 0000 0000 0000 0000 0000 0000 0000 >;>; 4 give

0000 1010 0000 0000 0000 0000 0000 0000

B.1010 0000 0000 0000 0000 0000 0000 0000 >;>; 4 give

1111 1010 0000 0000 0000 0000 0000 0000

C.1010 0000 0000 0000 0000 0000 0000 0000 >;>;>; 4 give

0000 1010 0000 0000 0000 0000 0000 0000

D.1010 0000 0000 0000 0000 0000 0000 0000 >;>;>; 4 give

1111 1010 0000 0000 0000 0000 0000 0000

45. Give following fragment.

Outer: for(int i=0; i<3; i++)

inner:for(int j=0;j<3;j++){

If(j>;1)break outer;

System.out.println(j+”and”+i);

}

Which will be output?

A. 0 and 0B. 0 and 1C. 0 and 2D. 0 and 3

E. 1 and 0F. 1 and 1G. 1 and 2H. 1 and 3

I. 2 and 0J. 2 and 1K. 2 and 2L. 2 and 3

46. Examine the following code which includes an inner class:

public final class Test4 implements A{

class Inner{

void test(){

if (Test4.this.flag);{

sample();

}

}

private boolean flag=false;

}

public void sample(){

System.out.println(“Sample”);

}

public Test4(){

(new Inner()).test();

}

public static void main(String args[]){

new Test4();

}

}

What is the result:

A.Print out “Sample”

B.Program produces no output but terminates correctly.

C. Program does not terminate.

E.The program will not compile

47. What is written to the standard output given the following statement:

System.out.println(4|7);

Select the right answer:

A.4B.5C.6D.7E.0

48. Look the inheritance relation:

person

|

----------------

| |

man woman

In a source of java have the following line:

person p=new man();

What statement are corrected?

A.The expression is illegal.

B.Compile corrected but running wrong.

C.The expression is legal.

D.Will construct a person’s object.

49. Look the inheritance relation:

person

|

----------------

| |

man woman

In a source of java have the following line:

woman w=new man():

What statement are corrected?

A.The expression is illegal.

B.Compile corrected but running wrong.

C.The expression is legal.

D.Will construct a woman’s object.

50.Which can NOT be used in declaring or declaring and initializing an automatic (method local) variable?

A. finalB. static C. expressions D. Constants of non-primitive type

E.initialized arrays (such as “ {“Hello”,”Good bye”}”).

51. Given the following incomplete method:

public void method(){

1)if (someTestFails()){

2)

3) }

4)

5)}

You want to make this method throw an IOException if,and only if,the method someTestFails() returns a value of true.

Which changes achieve this?

A.Add at line 2:IOException e;

B.Add at line 4:throw e;

C.Add at line 4:throw new IOException();

D.Add at line 6:throw new IOException();

E.Modify the method declaration to indicate that an object of type Exception might be thrown.

52.Given the following definition:

String s = null;

Which code fragments cause an object of type NullPointerException to be thrown?

A. if((s!=null)&(s.length()>;0))

B. if((s!=null)&&(s.length()>;0))

C. if((s==null)|(s.length()==0))

D. if((s==null)||(s.length()==0))

53.The following is a program

1)class Exsuper{

2) String name;

3) String nick_name;

4)

5) public ExSuper(String s,String t){

6) name = s;

7) nick_name = t;

}

9)

10)public string toString(){

11) return name;

12) }

13)}

14)

15)public class Example extends ExSuper{

16)

17)public Example(String s,String t){

1 super(s,t);

19)}

20)

21)public String to String(){

22) return name +”a.k.a”+nick_name;

23)}

24)

25)public static void main(String args[]){

26) ExSuper a = new ExSuper(“First”,”1st”);

27) ExSuper b = new Example(“Second”,”2nd”);

2

29)System.out.println(“a is”+a.toString());

30)System.out.println(“b is”+b.toString());

31) }

32)}

54.What happens when the user attempts to compile and run this program?

`A. A Compiler error occurs at line 21

B. An object of type ClassCastException is thrown at line 27

C.The following output:

a is First

b is second

D. The following output:

a is First

b is Second a.k.a 2nd

F.The following output:

a is First a.k.a 1st

b is Second a.k.a 2nd

55.Which statements are true about Listeners?

A.At most one listener can be added to any simple Component.

B.The return value from a listener is used to control the invocation of other listener

C.If multiple listeners are added to a single component, they must all be made friends to each other

D.If multiple listeners are added to single component, the order of invocation of the listener is not specified.

E.In the AWT, listener methods generally take an argument, which is an instance of some subclass of java.awt.AWTEvent class.

56.Given the following class outline:

class Example{

private int x;

// rest of class body

public static void main(String args[]){

//implementation of main mehtod}

}

Which statement is true?

A.x=2 is a valid assignment in the main() method of class Example.

B.Changing private int x to int x would make x=2 a valid assignment in the main() method of class Example.

C.Changing private int x to public int x would make x=2 a valid assignment in the main() method of class Example.

D.Changing private int x to static int x would make x=2 a valid assignment in the main() method of class Example.

E.Changing class Example to public class Example would make x=2 a valid assignment in the main() method of class Example.

57.Which statement is true about an inner class?

A.It must be anonymous

B.It can not implement an interface

C.It is only accessible in the enclosing class

D.It can access any final variables in any enclosing scope.

58.Which statement is true about the grid bag layout manager?

A.The number of rows and columns is fixed when the container is created.

B.The number of rows and columns is fixed when the GridBagLayout object is created.

C.If a component has a fill value of BOTH, then as the container change size, the component is resized.

D.Every component must carry a non-zero weightx and weighty value when it is added to the container

E.If a row has a weighty value that is non-zero, then as the container changes height, the row changes height.

59.Which statement are true about writing a class that is to handle the events issued by a user interface component.

A.Subclassing an adapter is inappropriate in this case.

B.The class should implement some listener interface

C.A class can implement multiple listener interfaces if desired.

D.A subclass of an AWT component cannot listen to its own events.

E.When implements listener interface, a class need only provide those handler methods that it chooses.

60.Which best describes the requirements of a fully encapsulated class?

A.Methods must not be private.

B.Variables must not be public.

C.The class must be marked final

D.Public methods are all marked final.

E.Modification of the objects state is only possible using method calls.

61.Which contains objects without ordering, duplication, or any particular lookup/retrieval mechanism?

A. MapB. SetC. ListD. CollectionE. Enumeration

62.What might cause the current thread to stop executing?

A.An interrupted exception is thrown.

B.The thread execute a sleep() call.

C.The thread constructs a new thread

D.A thread of higher priority becomes ready

E.The thread executes a read() call on InputStream

63.Which statements are true about threads?

A.Threads created from the same class all finish together.

B.A thread can be created only by subclassing java.lang.Thread.

C.Invoking the suspend() method stops a thread so that it cannot be restarted.

D.The Java interpreter’s natural exit occurs when no non-daemon threads remain alive.

E.Uncoordinated changes to shared data by multiple threads may result in the data being read, or left, in an inconsistent state.

64.What might FORM part of a correct inner class declaration or combined declaration and instantiation?

A.private class C

B.new SimpleInterface(){

C.new ComplexInterface(x){

D.private final abstract class(

E.new ComplexClass() implements SimpleInterface

65. Which statements are true about the garbage collection mechanisms?

A.The garbage collection mechanism release memory at pridictable times.

B.A correct program must not depend upon the timing or order of garbage collection

C.Garbage collection ensures that a program will NOT run out of memory during execution

D.The programmer can indicate that a reference through a local variable is no longer going to be used.

E.The programmer has a mechanism that explicitly and immediately frees the memory used by Java objects.

66. Given:

public class ReturnIt{

ReturnType methodA(byte x,double y){

return (short)x/y*2;

}

}

What is the valid return for methodA in line2?

A.int B. byte C. long D. short E. float F. double 转贴于 考试大 //www.examda.com

27e9a90e5ef2d044aafa2970aa5049e2.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值