Java initializes and clears objects

Source: Internet
Author: User

Initialization and cleanup
1. Use the builder for automatic initialization.
Java uses the builder to complete initialization. The Builder name is the same as the class name. The builder can also use User-Defined variables so that we can create specific methods for objects;
Class Rock {
Rock (int I ){
System. out. println (
"Creating Rock number" + I );
}
}
2. Method overload (heavy load)
I. Method-specific overload: Unique parameter list
2. Heavy Load of the primary type. The primary type can be converted to a larger type with a smaller value;
3. default constructor. The default constructor has no independent variables. Its role is to create an empty object. If a class without constructor is created, the compiler will create a default constructor for us.
4. This keyword. You can use the this keyword to obtain the handle of the current object within an object. If you call an object's method within an object, you can directly write the method. You do not need to fill in this.
5. Static keywords
We can fully understand the meaning of the static (static) method. It means that a specific method does not have this. We cannot call non-static methods from within a static method (comment ②), though it is also possible. In addition, without any objects, we can call a static method for the class itself. In fact, that is the most basic meaning of the static method. It is like creating an equivalent of a global function (in C ). Except that global functions cannot be used in Java, if a static method is placed inside a class, it can access other static methods and static fields.
Static methods are not "Object-Oriented" because they have some features of global functions. Using static methods, we do not have to send a message to the object because this does not exist.
 
 
This article is from the blog of "Zhao Zhijun's blog ".

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.