The answers to the questions in your eyes and the answers to the questions in Java's eyes (we're different)

Source: Internet
Author: User
Tags access properties c constructor modifier

First and everyone said the joke: a choice in your eyes, see a option well this question should be a, see B option B seems to be right ah, see C option C seems to have seen in the book, see D option This is not and a a meaning. Daniel Eye A option well this question is a, see B option Well this question is a look at the C option well this question is a see D option well this question is a This is the gap between you and Daniel-the basis and know why

1, the following statement is correct ()

A. Two public-modified classes can exist in a single file

B. Constructors can be overridden (override)

C. Subclasses cannot access properties of parent class non-public and protected adornments

D.final-Modified classes can be inherited

Answer: C

There can be at most one public class in a Java source file, and when there is a public class, the source file name must be the same, otherwise it cannot be compiled, and if there is no public class in the source file, the file name does not have a consistency requirement in the class. The main () does not have to be placed in the public class to run the program.

Overriding is when a subclass inherits a parent class and modifies the method of the parent class. The method name, parameter, and return value must be the same. You cannot override a method that is marked as final. If you cannot inherit a method, you cannot override this method.

Extension: overriding override, the difference between overloaded overload

Method overloading for Java

Is that you can create multiple methods in a class that have the same name but have different parameters and different definitions. The method is invoked by the number of different arguments and parameter types passed to them to determine which method to use, and the return value type can be the same or not the same, which is also object-oriented polymorphism.

Java method overrides

The polymorphism between the parent and child classes, redefining the functions of the parent class. If you define a method in a subclass that has the same name and arguments as its parent class, we say that the method is overridden (overriding). In Java, subclasses can inherit methods from the parent class without having to rewrite the same method. But sometimes subclasses do not want to inherit the parent class's methods, but want to make some changes, which requires a method of rewriting. Method overrides are also called method overrides.

If a method in a subclass has the same method name, return type, and parameter table as a method in the parent class, the new method overwrites the original method. If you need a method from the parent class, you can use the Super keyword, which references the parent class of the current class.

The access adornment permission of a subclass function cannot be less than the parent class;

Overriding methods can only exist in an inheritance relationship, overriding methods can only override the parent class's non-private methods.

2,for (int x=0,y=0; (y!=0) && (x<4); x + +) The number of executions of the loop is ()

A. Unlimited times

B. Execution 4 times

C. Implementation 3 times

D. No execution at a time

Answer: D

The y initial value is 0, in the entire for loop, the value of Y is not changed, so the judgment statement (Y!=0) is not established, it is not executed once.

3, about the JAVA heap, the following statement is wrong ()

A. Instances and arrays of all classes are allocated memory on the heap

B. The heap memory occupied by the object is reclaimed by the automatic memory management system

C. Heap memory consists of surviving and dying objects, free fragment area

D. Arrays are allocated in the stack

Answer: D

The first array is allocated in the heap, so the statement of D is incorrect.

Structure of the Java heap: The JVM heap is the run-time data area, and the instances and arrays of all classes are allocated memory on the heap. It is created when the JVM is started. The heap memory that the object occupies is reclaimed by the automatic memory management system, which is the garbage collector. Heap memory is made up of surviving and dying objects. The surviving objects are accessible to the app and are not garbage collected. The object of death is the object that the app is inaccessible and has not been reclaimed by the garbage collector. Until the garbage collector reclaims these objects, they will occupy the heap memory space.

4, when using the super and this keyword, the following description is correct ()

A. Use super () in the subclass construction method to display the constructor method of calling the parent class;

Super () must be written in the first row of the subclass construction method, otherwise the compilation does not pass

B.super () and this () do not have to be placed within the first line of the constructor method

C.this () and super () can appear in one constructor at a time

D.this () and super () can be used in a static environment, including static methods and static statement blocks

Answer: A

The Java keyword This can only be used in a method method body. When an object is created, the Java Virtual Machine (JVM) assigns a pointer to the object that refers to itself, which is the name of this pointer. Therefore, this can only be used in non-static methods in the class, and the static method and the static code block must never appear in this.

Super key is similar to this, is a masked member variable or member method or becomes visible, or is used to refer to a masked member variable and member member method.

However, super is used in subclasses in order to access the masked members in the immediate parent class, which is the immediate parent class (the closest superclass above the class)

5, which of the following statements is correct ()

A The Java program will generate machine code after compiling.

B The Java program generates a byte code after it is compiled

C A Java program compiles a DLL after it has been compiled

D None of the above is correct

Answer: B

Java bytecode is the intermediate file generated by the Java source file compilation

Java virtual machines are hypothetical computer Java that can run Java bytecode, and the cross-platform is also relative to other programming languages.

First introduce the C language of the compilation process: C file after the C compiler compiled after the generation of Windows executable EXE file and then execute in Windows.

Again, the Java compilation process: Java files are compiled by the Java program Java bytecode file is the class file in the Java Virtual machine execution. The machine code is executed by the CPU, and Java is compiled as a byte code.

The computer can only run machine code. Java turns bytecode into machine code when it is running. C + + compiles directly into machine code at compile time

With 1-5 working experience, in the face of the current popular technology do not know where to start, need to break through the technical bottleneck can add group. Stay in the company for a long time, have a very comfortable, but job-hopping interview wall. Need to study in a short period of time, job-hopping to get a high salary can add group. If there is no work experience, but the foundation is very solid, on the Java work mechanism, common design ideas, Common Java Development Framework Master skilled can add group. Java Architecture Group: 5,912,408,171 communication.

6, which of the following statements is true ()

A The abstract modifier modifies fields, methods, and classes

B The body part of the abstract method must be wrapped in a pair of curly braces {}

C Declaring abstract methods, curly braces are optional

D Declaring abstract methods cannot write curly braces

Answer: D

The abstract modifier is used to decorate classes and Member methods

An abstract class is represented by a class that is abstracted, and the abstract class is located in the abstraction layer of the inheritance tree, and the abstract class cannot be instantiated.

Abstract methods are used to represent abstractions, and there is no method body for abstract methods. Abstract methods are used to describe what functions the system has, but do not provide specific implementations.

Abstract is an important keyword in Java that can be used to decorate a class or a method.

When a method is decorated, it means that the method has only signature signatures (signature), there is no specific implementation, but rather a specific implementation is left to inherit the subclass of the class, so there cannot be curly braces.

7, the following statements are correct ()

A The constructor in class must not be omitted

B Constructor must have the same name as class, but the method cannot have the same name as class

C constructor is executed when an object is new

D A class can only define one constructor

Answer: C

There may be misunderstandings here, in fact, the ordinary class method can be the same name as the class names, and the construction method is the only distinction is that the construction method does not return a value.

Whether the 8,GC thread is a daemon thread ()

Answer: Yes

Threads are divided into daemons and non-daemon threads (that is, user threads).

The daemon thread works as long as any non-daemon thread in the current JVM instance is not finished, and the daemon ends up working with the JVM only when the last non-daemon thread ends.

The most typical application for daemon threads is the GC (garbage collector)

9, about sleep () and wait (), one of the following descriptions of the error is ()

A. Sleep is a thread-class method, and wait is a method of the object class;

B. Sleep does not release object locks, wait to discard object locks;

C. Sleep pauses the thread, but the monitoring State remains, and the end is automatically restored;

D. Wait to enter the waiting lock pool, only after the Notify method is issued for this object to get the object lock into the running state.

Answer: D

Sleep is a threading class (thread) method that causes this thread to pause execution for a specified time, giving the execution opportunity to other threads, but the monitoring state remains and is automatically restored when it is finished. Calling sleep does not release the object lock.

Wait is a method of the object class that calls the wait method on this object to cause this thread to discard the object lock, enter the waiting lock pool waiting for this object, and only after the Notify method (or Notifyall) is issued for this object the thread enters the object lock pool ready to get the object lock into the running state.

10, Method Resume () is responsible for recovering which threads are executing ()

A, a thread that stops by calling the Stop () method.

B, the thread that is stopped by calling the sleep () method.

C, the thread that is stopped by calling the Wait () method.

D, the thread stopped by calling the Suspend () method.

Answer: D

Suspend can suspend a thread, which is to suspend the thread, it occupies the resource, but does not run, with resume is to resume the suspended thread, let this thread continue to execute.

11, about the role of Spring MVC's core controller Dispatcherservlet, the following statement is wrong ()

A, it is responsible for receiving HTTP requests

B, load the configuration file

C, enabling business operations

D, initialize the upper and lower application objects ApplicationContext

Correct answer: C

SPRINGMVC is a module in spring that implements the MVC design pattern, where the user initiates the request and requests the SPRINGMVC Front Controller (dispatcherservlet) to reach the Based on the user's URL request processor Mapper, the front-end controller looks for a handle that matches the URL, returns an execution chain, and then requests the processor adapter to call the appropriate handle to process and return to the front controller a Modelandview, The front controller then requests the view resolver to parse the returned logical view, and the last front controller renders the returned view and loads the data into the request domain and returns it to the user.

Dispatcherservlet as the front-end controller of the SPRINGMVC, is responsible for receiving the user's request, and returns the corresponding view to the user according to the user's request. Implement business at the service layer, so C answer is wrong.

12, the following about spring's dependency injection, the saying is wrong ()

A, dependency injection usually has the following two kinds: Set value injection and construct injection:

B, construction injection can determine the injection order of dependencies in the constructor, priority-dependent injection

C, when the value injection and the construction injection exist simultaneously, the construction injection is performed first, and then the value injection is performed.

D, value injection means that the IOC container uses the setter method of the attribute to inject the dependent instance. This injection method is simple and intuitive

Correct answer: C

When using constructor dependency injection, spring guarantees that all dependent objects of an object are instantiated before instantiating the object. When using the Set method dependency injection, spring instantiates the object first and then instantiates all dependent objects.

When the value injection and the construction injection exist simultaneously, the value injection is performed first and then the construction injection is performed.

13, configure the metadata to the spring container, which of the following methods is incorrect ()

A, by grouping and solving groups of objects

B, annotation base configuration

C,java Basic Configuration

D,xml Basic Configuration

Correct answer: A

There are three ways to provide metadata to the spring container: The 1,xml configuration file, 2, based on the annotation configuration, and 3, based on the Java configuration, the dead concept can be remembered.

14, which of the following is not a spring annotation ()

A, @Aspect

B, @Service

C, @Component

D, @Controller

E, @View

Correct answer: E

Review the familiarity with spring, which is a more common annotation than the E option.

15, the following about the transaction propagation characteristics of spring, it is wrong to say ()

A,propagation_supports: Supports the current transaction, if no transaction is currently in use and is executed in a non-transactional manner

B,propagation_required: Supports the current transaction and throws an exception if there is no current transaction

C,propagation_requires_new: New transaction, suspend current transaction if current transaction exists

D,propagation_nested: Supports current transaction, new SavePoint point, synchronous commit or rollback with current transaction

Correct answer: B

The propagation properties of a transaction are described:

Propagation_required--Supports the current transaction and creates a new transaction if there is no current transaction. This is the most common choice.

Propagation_supports-supports the current transaction and is executed in a non-transactional manner if no transaction is currently in use.

The propagation_mandatory--supports the current transaction and throws an exception if there is no current transaction.

Propagation_requires_new--Creates a new transaction and suspends the current transaction if there is a transaction currently in place.

Propagation_not_supported--Performs the operation in a non-transactional manner, suspending the current transaction if a transaction is currently present.

Propagation_never--executes in a non-transactional manner and throws an exception if a transaction is currently present.

16, the following about the IOC description error in the spring feature is ()

A,ioc means that the relationship between programs is manipulated directly by the program code.

B, the so-called "control reversal" refers to the transfer of control from the application code to the external container, that is, the control right

C,IOC the responsibility of controlling the creation into the framework, separating from the application code

D, when using the spring IOC container, only the objects required by the component are indicated, and at runtime the IOC container of spring is provided to it based on the XML configuration data

Correct answer: A

The IOC, the control reversal (inversion of the English abbreviation for IOC), is an important object-oriented programming law that cuts the coupling of computer programs and is also the core of the lightweight spring framework. Control reversals are generally divided into two types, dependency injection (Dependency injection, short di), and dependent lookup (Dependency lookup).

The answers to the questions in your eyes and the answers to the questions in Java's eyes (we're different)

Related Article

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.