The foundation is the top priority ~ How is the class executed?

Source: Internet
Author: User

Back to directory

ForProgramPersonnel, it is necessary to know a concept and understand its execution process, which is helpful for writing better and safer programs.

It's not just a day for the ox, but a step-by-step practice that keeps accumulating knowledge.

Today is my "foundation is the top priority"ArticleAnother lecture of the series is also the most basic one.

Let's talk about it from birth to death.

Class 1 Creation

Public class person {

Static person () {}// do not write, there is also an empty by default

Public Person () {}// do not write, there is also an empty by default

Public string name {Get; private set;} // attribute. Write Permission is only available for this class.

}

In this way, a person will generate, note that it will have two constructor methods at the same time, static person () {}and public person () {}, both of which are empty parameters, their names are respectively the Type constructor method and the instance constructor method. We can know from the name that the first method is only public to this class, it is a method that can be accessed by static members in the class. The second public person () is executed after the class is new to an object (instance, therefore, it is called an instance constructor.

The execution sequence is static first, followed by other constructor methods.

Class 2 Declaration and instantiation

Person = new person ();

In this way, a class object named person is created. When it is created, the public person () constructor is first executed.

3. Use class attributes and Methods

Person. Name = "zzl"; this statement is incorrect, because the name attribute of the person object only has write permission for itself.

4. The object is recycled by GC.

GC, a managed item, is responsible for recycling unused objects.

Back to directory

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.