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 ".