Wrong question 724

Source: Internet
Author: User

1. Code snippet:

BYTE B1=1,b2=2,b3,b6; Final byte b4=4,b5=6; B6=B4+B5; B3= (B1+B2); System.out.println (B3+B6);

The description of the above code snippet is correct ()

A. Output results: 13

B. Statement: B6=B4+B5 compilation error
C. Statement: B3=B1+B2 compilation error
D. Run-time exception thrown
The correct answer is: C,
The parsing is as follows:
The final modified variable is a constant, where the b6=b4+b5 can be seen as b6=10, and at compile time it becomes b6=10 and B1 and B2 are byte types, which are evaluated in Java as an int type, then computed, b1+ The B2 is already an int type, the assignment to B3,b3 is a byte type, the type does not match, the compilation does not pass, and a cast is required.   Byte,short,char in Java is promoted to the int type when it is evaluated. 2. Regarding abstract and final classes, the following statements are wrong?
A. An abstract class can be inherited, and the final class can only be instantiated.
B. Abstract classes and final classes can be declared using
C. Abstract classes can have no abstract method, the final class can have no final method
D. When an abstract class and a final class are inherited, the method can be overridden by the quilt class

The answer is: D
The parsing is as follows:
1, abstract classes can have an abstract method, or there can be no abstract method. 2, the abstract class can of course be inherited, because it is used to inherit, 3, inherit the abstract class, if there is an abstract method, the subclass must be its abstract method implementation, 4, abstract class non-abstract method can be overridden. The final class and abstract class is exactly the opposite 5, plus the final class is called the final class, plus the final method is called the final method, 6, the final class can have the final method or No 7, the final class cannot have subclasses, the final method can not be overridden by the type of 3.Java program has ( ) A. Class (Class) B.appletc.applicationd.servlet answer: B C D Parse:

The types of Java programs are:

(a) embedded in a Web file, viewed by a browser _applet

(b) application that can be operated independently

(c) Server-side Servlets

In 4.Java languages, the rewriting of methods (overriding) and overloads (overloading) are different manifestations of polymorphism. Which of the below statements is true?

A. Overrides are a representation of polymorphism between a parent class and a subclass.

B. Rewriting is a representation of polymorphism in a class.

C. Overloading is a representation of polymorphism in a class

D. Overloading is a representation of polymorphism between a parent class and a subclass.

Correct answer: A C my answer: a B C (error)

Parsing: A C rewrite (overriding) is a representation of the polymorphism between the parent class and the subclass, and the different implementations of the class can override the parent class method, implementing the same method name, the same parameter, the same return type, and different implementations. Overloading (overloading) is the most typical of a class of different constructors, the same method name, the number of parameters, the return type can also be different, overloading is a class of polymorphism of a performance.

5.final, finally and finalize the difference between the following statement is correct?

A.final is used to declare properties, methods, and classes, respectively, that the property is not mutable, that methods are not overridden, and that classes are not inheritable.
B.finally is part of the exception-handling statement structure, which indicates that it is always executed.
C.finalize is a method of the object class that, when executed by the garbage collector, calls this method of the reclaimed object, and can override this method to provide recycling of other resources when garbage collection, such as closing a file.
D. After the reference variable is final decorated, it can no longer point to other objects, and the content of the object it points to is immutable.

Correct answer: A b c my answer: a b C D (Error)

Analytical:
D is wrong for the following reasons: public class strict Total {int ttt = 0;public static void Main (String argv[]) {Strict total test = new strict total (); final strict total F = test;//f = test; Compile error, cannot just want other object f.ttt = 1;//can modify content, so D is wrong System.out.println ("ttt=" + f.ttt);} When you use the final keyword to decorate a variable, it means that the reference variable cannot be changed, and the contents of the object to which the reference variable is pointing can be changed. 6. The following description of forward and redirect, right?
A.forward is the server that transfers control to another internal server object, and the new object is solely responsible for responding to the user's request
B. When executing forward, the browser does not know where the server sends the content from, the browser address bar or the original address
C. When executing redirect, the server tells the browser to re-request the address
D.forward is an internal redirect, redirect is an external redirect
E.redirect default generates an HTTP response for 301 permanently moved

Analytical:
1. From the Address bar display, forward is the server requests the resource, the server directly accesses the URL of the destination address, reads the response content of that URL, and then sends the content to the browser. The browser doesn't know where the server sent the content from, So its address bar is still the original address. Redirect is the server based on logic, sending a status code that tells the browser to re-request that address. So the address bar shows a new URL. 2. Forward from data sharing: forward pages and forwarded pages can share data within the request. REDIRECT: Data cannot be shared. 3. From the point of use forward: generally used when the user login, according to the role of forwarding to the corresponding module. REDIRECT: Generally used for users to log off when logging back to the main page and jump to other sites and so on. 4. Forward from efficiency: high. REDIRECT: Low.
The life cycle of the 7.Servlet can be divided into the initialization phase, the run phase and the destruction phase three phases, the following process belongs to the initialization phase ().
A. Loading data for the Servlet class and. Class
B. Creating Serletrequest and Servletresponse objects
C. Creating a ServletConfig object
D. Creating a Servlet object

Correct answer: A C D

Analytical:

The life cycle of a servlet can typically be expressed in three ways:

    1. Init (): Executes only once and is responsible for initializing the Servlet object when the servlet is loaded
    2. Service (): The core method, General HttpServlet will have get,post two kinds of processing methods. The ServletRequest and Servletresponse request and response objects are constructed as parameters when the Doget and Dopost methods are called.
    3. Destory (): Executes when a servlet is stopped and unloaded, responsible for freeing resources

Initialization phase: The servlet starts, reads information from the configuration file, constructs the specified Servlet object, creates a ServletConfig object, and invokes the Init () method as a parameter for ServletConfig. So choose ACD. B is constructed only when the service method is invoked

Servlet (Server Applet), full name Java Servlet, without Chinese translation. is a server-side program written in Java. Its main function is to interactively browse and modify data to generate dynamic Web content. The narrow-sense servlet refers to the Java language implementation of an interface, the generalized servlet refers to any implementation of the Servlet interface class, in general, people will understand the servlet as the latter. The servlet runs in a Java-enabled application server. In principle, servlets can respond to any type of request, but in most cases the servlet is used only to extend the HTTP protocol-based Web server. This process is: 1) The client sends the request to the server side; 2) the server sends the request information to the servlet; 3) The servlet generates the response content and passes it to the server. The response content is dynamically generated, usually depending on the client's request; 4) The server returns the response to the client.

The life cycle of a servlet can be divided into three stages of the initialization phase, the run phase and the destruction phase, and the following process belongs to the initialization phase of 1.load the servlet class and the data corresponding to the. Class2.Create a ServletConfig object3.Create a Servlet objectEach time the request arrives at the container, the HttpServletRequest and Httpservlceresponse objects are generated and passed in as arguments when the service () method is called. After the Web container is started, the servlet settings information is read, the servlet class is loaded and instantiated, and a ServletConfig object is created for each servlet setting information, and then the Init () method of the Servlet interface is called. The resulting ServletConfig object is passed as a parameter.

Wrong question 724

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.