Basic run order of the 5.Java class

Source: Internet
Author: User

We use the following class to illustrate the order in which a basic Java class is run:

  1. Public class Demo{
  2. Private String name;
  3. Private int age;
  4. Public Demo(){
  5. Name = "Micro School";
  6. Age = 3;
  7. }
  8. Public static void main(String[] args){
  9. Demo obj = New demo();
  10. System. Out. Theage of println (obj. Name + "is" + obj.);
  11. }
  12. }

The basic run order is:

    1. First, run to line 9th, which is the entrance to the program.
    2. Then run to line 10th, where a new demo is called to call the demo's construction method.
    3. Run To line 5th, note: Many people may think that the next line should be run 6th, wrong! To initialize a class, you must first initialize its properties.
    4. So run to line 2nd, then line 3rd.
    5. After the initialization of the property, the constructor is returned to the code, which is the 6th line and the 7th line.
    6. Then the 8th line indicates that the new demo instance is complete.
    7. Then go back to the main method and execute line 11th.
    8. Then the 12th line, and the main method executes.


As a programmer, it should be clear that the basic process of operation, otherwise confused, not conducive to writing code, but also not conducive to technical development.

Basic run order of the 5.Java class

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.