What happens behind the new DerivedClass () in Java
Source: Internet
Author: User
What happens behind the new DerivedClass () in Java
(Original – Shoheng, 2005-4-5)
Class DerivedClass extends BaseClass {...}
New DerivedClass ();
1 Load Class
1.1 Loading BaseClass produces recursion for the sequence steps described here (that is, load Class).
1.2 Load into DerivedClass
1.2.1 Allocates storage space for class scope variables and assigns default values
1.2.2 calls <cinit>, which includes: a). Statement b that declares the class scope variable and assigns the value at the same time. An assignment statement contained in static {...} and any other legitimate statement. To illustrate: the right value of the above assignment statement can also be a function call, which is legal.
2 Allocate storage space for the instance scope variable and assign a default value.
3 Calling Constructors * * * Note: Java rule: The first statement of a constructor must be a call to a super constructor, and if not, the compiler automatically adds it secretly.
3.1 Invokes the Super constructor, resulting in recursion of the sequence steps described here (that is, calling the constructor).
3.2 Call <init>, which includes: a). Statement b that declares an instance scope variable and assigns a value at the same time. The assignment statement contained in {..} and any other legitimate statement. To illustrate: the right value of the above assignment statement can also be a function call, which is legal.
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