assert value == null;
assert value != null, value is null;
if (value == null) { throw new AssertionException(value is null); }
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.
第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");}
第3题:
A.assertvalue==null;
B.assertvalue!=null:"valueisnull";
C.if(value==null){thrownewAssertionException("valueisnull");}
D.if(value==null){thrownewIllegalArgumentException("valueisnull");}
第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?()
第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?()
第6题:
A.assertvalue==null;
B.assertvalue!null,“valueisnull”;
C.if(value==null){thrownewAssertionException(”valueisnull”);
D.if(value==null){thrownewIllegalArgumentException(”valueisnull”);
第7题:
A. 0
B. 1
C. No Object
D. 编译错误
E. null
第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
第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?()
第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?()