Java认证考试

Given the following code fragment:     public void create() {     Vector myVect;     myVect = new Vector();      }  Which of the following statements are true?() A、 The declaration on line 2 does not allocate memory space for the variable myVect.B、 The d

题目

Given the following code fragment:     public void create() {     Vector myVect;     myVect = new Vector();      }  Which of the following statements are true?() 

  • A、 The declaration on line 2 does not allocate memory space for the variable myVect.
  • B、 The declaration on line 2 allocates memory space for a reference to a Vector object.
  • C、 The statement on line 2 creates an object of class Vector.
  • D、 The statement on line 3 creates an object of class Vector.
  • E、 The statement on line 3 allocates memory space for an object of class Vector.
如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

Which of the following is a disadvantage of using the EIGRP protocol?()

A. It does not scale well

B. It converges slower than OSPF

C. It is a proprietary protocol

D. It is a distance vector protocol


参考答案:C

第2题:

1. public class a {  2. public void method1() {  3. try {  4. B b=new b();  5. b.method2();  6. // more code here  7. } catch (TestException te) {  8. throw new RuntimeException(te);  9. }  10. }  11. }  1. public class b {  2. public void method2() throws TestException {  3. // more code here  4. }  5. }  1. public class TestException extends Exception {  2. }  Given:  31. public void method() {  32. A a=new a();  33. a.method1();  34. }  Which is true if a TestException is thrown on line 3 of class b?()

  • A、 Line 33 must be called within a try block.
  • B、 The exception thrown by method1 in class a is not required to be caught.
  • C、 The method declared on line 31 must be declared to throw a RuntimeException.
  • D、 On line 5 of class a, the call to method2 of class b does not need to be placed in a try/catch block.

正确答案:B

第3题:

给出下面的代码段,下面的哪些陈述为真? ( ) public void create() { Vector myVect; myVect=new Vector(); } Ⅰ:第2行的声明不会为变量myVect分配内存空间。 Ⅱ:第2行的声明分配一个到Vector对象的引用的内存空间。 Ⅲ:第2行语句创建一个Vector类对象。 Ⅳ:第3行语句创建一个Vector类对象。

A.Ⅱ、Ⅲ、Ⅳ

B.Ⅱ、Ⅲ、Ⅳ

C.Ⅰ、Ⅲ

D.Ⅰ、Ⅳ


正确答案:D
解析:本题是考查对Vector的应用和理解。要为一个新对象分配空间,必须执行new Xxx()调用,new调用执行以下的操作:首先为新对象分配空间并将其成员初始化为0或者null:执行类体中的初始化(如在类中有一个成员声明int a=10,在第1步后a=O,执行到第2步后 a=10);然后执行构造函数;最后变量被分配为一个到内存堆中的新对象的引用。

第4题:

Given the following code:     1) public void modify() {     2) int i, j, k;     3) i = 100;     4) while ( i > 0 ) {     5) j = i * 2;  6) System.out.println (" The value of j is " + j );     7) k = k + 1;     8) i--;     9) }  10) }  Which line might cause an error during compilation?()   

  • A、 line 4
  • B、 line 6
  • C、 line 7
  • D、 line 8

正确答案:C

第5题:

You create a Microsoft ASP.NET application by using the Microsoft .NET Framework version 3.5. You create a page that contains the following code fragment:       You write the following code segment in the code-behind file for the page:   void BindData(object sender, EventArgs e) {   lstLanguages.DataSource =  CultureInfo.GetCultures(CultureTypes.AllCultures);   lstLanguages.DataTextField = "EnglishName";  lstLanguages.DataBind();   }   You need to ensure that the lstLanguages ListBox control maintains the selection of the user during postback.  Which line of code should you insert in the constructor of the page?()

  • A、this.Init += new EventHandler(BindData); 
  • B、this.PreRender += new EventHandler(BindData); 
  • C、lstLanguages.PreRender += new EventHandler(BindData); 
  • D、lstLanguages.SelectedIndexChanged += new EventHandler(BindData);

正确答案:A

第6题:

Which of the following is a disadvantage of using the EIGRP protocol?()

  • A、It does not scale well
  • B、It converges slower than OSPF
  • C、It is a proprietary protocol
  • D、It is a distance vector protocol

正确答案:C

第7题:

Which lines of code are valid declarations of a native method when occurring within the declaration of the following class?()    public class Qf575 {   // insert declaration of a native method here   }  

  • A、native public void setTemperature(int kelvin);
  • B、private native void setTemperature(int kelvin);
  • C、protected int native getTemperature();
  • D、public abstract native void setTemperature(int kelvin);
  • E、native int setTemperature(int kelvin) {}

正确答案:A,B

第8题:

Given:Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ?()

A.move the line 12 print statement into the foo() method

B.change line 7 to public synchronized void go() {

C.change the variable declaration on line 2 to private volatile int x;

D.wrap the code inside the foo() method with a synchronized( this ) block

E.wrap the for loop code inside the go() method with a synchronized block synchronized(this){ //for loop code here }


参考答案:A, D

第9题:

1. public class A {  2. public void method1() {  3. B b=new B();  4. b.method2();  5. // more code here  6. }  7. }  1. public class B {  2. public void method2() {  3.C c=new C();  4. c.method3();  5. // more code here  6. }  7. }  1. public class C {  2. public void method3() {  3. // more code here  4. }  5. }  Given:  25. try {  26. A a=new A();  27. a.method1();  28. } catch (Exception e) {  29. System.out.print(”an error occurred”);  30. }  Which two are true if a NullPointerException is thrown on line 3 of class C?()

  • A、 The application will crash.
  • B、 The code on line 29 will be executed.
  • C、 The code on line 5 of class A will execute.
  • D、 The code on line 5 of class B will execute.
  • E、 The exception will be propagated back to line 27.

正确答案:B,E

第10题:

package foo;  import java.util.Vector; private class MyVector extends Vector {  int i = 1;  public MyVector() {  i = 2; } }  public class MyNewVector extends MyVector {  public MyNewVector() {  i = 4;  }  public static void main(String args[]) {  MyVector v = new MyNewVector();  }  }  What is the result?()

  • A、 Compilation succeeds.
  • B、 Compilation fails because of an error at line 5.
  • C、 Compilation fails because of an error at line 6.
  • D、 Compilation fails because of an error at line 14.
  • E、 Compilation fails because of an error at line 17.

正确答案:B

更多相关问题