单选题Given a method that must ensure that its parameter is not null: 11. public void someMethod(Object value) { 12. // check for null value ... 20. System.out.println(value.getClass()); 21. } What inserted at line 12, is the appropriate way to handle a null

题目
单选题
Given a method that must ensure that its parameter is not null: 11. public void someMethod(Object value) { 12. // check for null value ... 20. System.out.println(value.getClass()); 21. } What inserted at line 12, is the appropriate way to handle a null value?()
A

assert value == null;

B

assert value != null, value is null;

C

if (value == null) { throw new AssertionException(value is null); }

D

if (value == null) { throw new IllegalArgumentException(value is null); }

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

public static void main(String[]args){String str="null";if(str==null){System.out.println("null");}else(str.length()==0){System.out.println("zero");}else{System.out.println("some");}}What is the result?()

A.null

B.zero

C.some

D.Compilationfails.

E.Anexceptionisthrownatruntime.


参考答案:D

第2题:

Givenamethodthatmustensurethatitsparameterisnotnull:11.publicvoidsomeMethod(Objectvalue){12.//checkfornullvalue...20.System.out.println(value.getClass());21.}Whatinsertedatline12,istheappropriatewaytohandleanullvalue?()

A.assertvalue==null;

B.assertvalue!=null,"valueisnull";

C.if(value==null){thrownewAssertionException("valueisnull");}

D.if(value==null){thrownewIllegalArgumentException("valueisnull");}


参考答案:D

第3题:

Givenamethodthatmustensurethatitsparameterisnotnull:What,insertedatline12,istheappropriatewaytohandleanullvalue?()

A.assertvalue==null;

B.assertvalue!=null:"valueisnull";

C.if(value==null){thrownewAssertionException("valueisnull");}

D.if(value==null){thrownewIllegalArgumentException("valueisnull");}


参考答案:D

第4题:

10. public Object m() { 11. Object o = new Float(3.14F); 12. Object [] oa = new Object[1]; 13. oa[0] = o; 14. o = null; 15. return oa[0]; 16. } When is the Float object, created in line 11, eligible for garbage collection?()  

  • A、 Just after line 13.
  • B、 Just after line 14.
  • C、 Never in this method.
  • D、 Just after line 15 (that is, as the method returns).

正确答案:C

第5题:

Given the definition of MyServlet: 11.public class MyServlet extends HttpServlet { 12.public void service(HttpServletRequest request, 13.HttpServletResponse response) 14.throws ServletException, IOException { 15.HttpSession session = request.getSession(); 16.session.setAttribute("myAttribute","myAttributeValue"); 17.session.invalidate(); 18.response.getWriter().println("value=" + 19.session.getAttribute("myAttribute")); 20.} 21.} What is the result when a request is sent to MyServlet?()

  • A、An IllegalStateException is thrown at runtime.
  • B、An InvalidSessionException is thrown at runtime.
  • C、The string "value=null" appears in the response stream.
  • D、The string "value=myAttributeValue" appears in the response stream.

正确答案:A

第6题:

publicvoidsomeMethod(Objectvalue){12.//checkfornullvalue....20.System.out.println(value.getClass());21.}What,insertedatline12,istheappropriatewaytohandleanullvalue?()

A.assertvalue==null;

B.assertvalue!null,“valueisnull”;

C.if(value==null){thrownewAssertionException(”valueisnull”);

D.if(value==null){thrownewIllegalArgumentException(”valueisnull”);


参考答案:D

第7题:

以下程序的运行结果为:public class My{int value;public static void main(String args[]) {My x=new My();if (x==null)System.out.println("No Object");elseSystem.out.println(x.value);}}

A. 0

B. 1

C. No Object

D. 编译错误

E. null


正确答案:A

第8题:

1.public class GC{2.private Objec to;3.private void doSomethingElse(Object obj){o=obj;}4.public void doSomething(){5.Object o=new Object();6.doSomethingElse(o);7.o=new Object();8.doSomethingElse(null);9.o=null;10.}11.}When the doSomething method is called,after which line does the Object created in line 5 become available for garbage collection?()

A.Line5

B.Line6

C.Line7

D.Line8

E.Line9

F.Line10


参考答案:D

第9题:

public static void main(String[] args) {  String str = “null‟;  if (str == null) {  System.out.println(”null”);  } else (str.length() == 0) {  System.out.println(”zero”);  } else {  System.out.println(”some”);  }  }  What is the result?()

  • A、 null
  • B、 zero
  • C、 some
  • D、 Compilation fails.
  • E、 An exception is thrown at runtime.

正确答案:D

第10题:

12. void start() {  13. A a = new A();  14. B b = new B();  15. a.s(b);  16. b = null;  17. a = null;  18. System.out.println(“start completed”); 19. }  When is the B object, created in line 14, eligible for garbage collection?()  

  • A、 After line 16.
  • B、 After line 17.
  • C、 After line 18 (when the methods ends).
  • D、 There is no way to be absolutely certain.
  • E、 The object is NOT eligible for garbage collection.

正确答案:D

更多相关问题