Java (2), java (2)

Source: Internet
Author: User

Java (2), java (2)

  • Briefly describe the operating mechanism of the constructor

The first thing to note is that the constructor is not a function, so it cannot be inherited. This is common when we write sub-class constructor in extends, even if the sub-class constructor parameters are exactly the same as those of the parent class, we need to write super for this reason.

The constructor modifier is limited. Only the public private protected modifier is available. Other modifiers such as public private protected cannot be used, that is to say, the constructor is not allowed to be abstracted, synchronized, static, and other access restrictions.

Because the constructor is not a function, it does not return a value or allow a return value. However, it should be noted that the constructor allows a return statement, but the return statement does not return anything. If you specify the return value, although the compiler will not report any errors, however, the JVM will think that it is a function with the same name as the constructor. In this case, some inexplicable errors cannot be found in the constructor. pay more attention to this.

Java sequence when constructing an instance

The rough process of construction is as follows:

1. Allocate the object space and initialize the object members to 0 or null. java does not allow users to manipulate an object with an indefinite value.

2. Execute Explicit initialization of attribute values (there is a slight change here, which will be explained later, but it is generally like this)

3. Execution Constructor

4. Associate variables with objects in the heap.

  • What are the differences between member variables and local variables?

(1) member variables can be modified by modifiers such as public, protect, private, and static, while local variables cannot be controlled or static. Both can be defined as final.

(2) member variables are stored in the heap, and local variables are stored in the stack.

(3) The existence time is different.

(4) member variables have default values. (if they are modified by final and are not static, they must be explicitly assigned .)

  • What is encapsulation? What are the characteristics of encapsulation?

Encapsulation is a manifestation of JAVA's object-oriented features. encapsulation is an information hiding technology that has two meanings: combining all attributes of an object with all services, form an inseparable independent unit and hide the internal structure of the object as much as possible. encapsulation features: parts other than the object cannot freely access the internal data of the object, this effectively avoids the "cross-infection" of external errors, so that software errors can be localized, greatly reducing the difficulty of error detection and troubleshooting.

  • Briefly describe the use and function of the final Modifier

The final modifier usually uses uppercase when defining constants. A Final constant can be declared with an initial value or an initial value in the constructor. In short, it must be initialized before use and can be assigned only once. To ensure that the behavior of a function remains unchanged during the inheritance process and cannot be overwritten, you can use the final method. Classes described by final are not allowed to be inherited.

I am the dividing line of tiantiao


Java foreign company pen Question 2, I did a wrong question. Can you see it? (Single choice, multiple choice)

Question 18th: After I have done this, both A and C can get the answer. However, C has A semantic problem and does not need group by name. Therefore, the final answer is, after several discussions in the QQ group, we finally decided it was.

How to pass the java Test

1. Contact Basics
2. Find an interview book
3. Write questions online ..
Good luck with you...

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.