Java classic Review

Source: Internet
Author: User
Code:
// Insect. Class
Package test;

Class insect {
Int I = 9;
Int H = Y1;
Static int Y1 = 8;
Int J;

Insect (){
PRT ("I =" + I + ", j =" + J );
J = 39;
}

Static int X1 = PRT ("static insect. X1 initialized ");

Static int PRT (string s ){
System. Out. println (s );
Return 47;
}
}

// Beetle. Class
Public class beetle extends insect {
Int K = PRT ("beetle. K initialized ");

Beetle (){
PRT ("k =" + k );
PRT ("J =" + J );
}

Static int X2 = PRT ("static beetle. X2 initialized ");

Public static void main (string [] ARGs ){
PRT ("beetle constructor ");
Beetle B = new beetle ();

}
}
/* 1. First, try to access beetle. Main (). This is a static method.
* 2. Go outside and find the code beetle. Class compiled for the beetle class.
* 3. Beetle is found to have a base class during beetle. class loading.
* 4. Initialize base class
* 1) initialize static
* 2) initialize common variables in the text order.
* 5. Initialize a derived class
* 1) initialize static
* 2) initialize common variables in the text order.
* 6. Execute the main program in main (in the text order)
* 1) PRT ("beetle constructor ");
* 2) instantiate a derived class (beetle B = new beetle ();)
* 1) base class Constructor
* 2) constructor of the derived class
*
* Test site: static variable initialization and access; use of Constructors
**/

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.