Java Fundamentals: Initialization and cleanup

Source: Internet
Author: User

(1) Initialize:

So if the inheritance relationship is: A export B and then export C, the order in which the C objects are created is:

* (1) A the static domain, B the static domain, C the static domain;

* (2) A the non-static domain, A the constructor, B the non-static domain, B the constructor, C the non-static domain, C the constructor


(2) Cleaning:

The order of destruction should be reversed from the order of initialization.


(3) Super/this

The method of the parent class can be called through the Super keyword in a subclass. You can also call your own method through the This keyword.

In the constructor, however, the super and the This keyword can exist only one, and are placed in the first sentence of the constructor function.

If c inherits from B,b and inherits from a, if you want to call the method of a in C method, it is not feasible to try to call through Super.super.method () only by creating an object of a, because Super does not allow two or more consecutive calls.

Java Fundamentals: Initialization and cleanup

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.