In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Constructors and destructors are two special methods in an object, both of which are related to the life cycle of the object. The constructor is the first method that is automatically called by the object after the object is created, which is why we use the constructor in the object. The destructor is the last method that is automatically called by the object before it is destroyed, which is why we use the destructor in the object. Therefore, constructors are usually used to initialize some objects, and destructors are used to clean up some objects before destruction.
1. Construction method
The format for declaring a constructor in a class is as follows:
Function _ _ construct (argument list) {/ / the constructor name is _ _ construct () starting with two underscores.
/ / method body, which is usually used to initialize the assignment of member attributes
}
The result of the code running is as follows:
2. Destructing method
The declaration format of a destructor is similar to that of a constructor, and the name of the destructor declared in the class is also fixed, with the method name "_ _ destruct" beginning with two underscores, and the destructor cannot take any parameters. The format for declaring a destructor in a class is as follows:
Function _ _ destruct () {/ / the name of the destructor is _ _ destruct () starting with two underscores.
/ / method body, which is usually used to complete some cleaning tasks before the object is destroyed
}
The result of running the code is:
Because the references of the objects are stored in the stack memory, because of the last-in-first-out characteristics of the stack, the last created object reference will be released first, so the destructor of the third object is automatically called first. finally, the destructor of the second object is automatically called.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.