I. Classes and objects
1. Encapsulation class
public class class Name {
Defining properties
Private data type variable name
Defining methods
Public return value type method name (parameter name) {
Concrete implementation of the method}
}
2. Create object: Call the constructor with the new keyword to create an object
Construction method: is a very special method, the method name and the class name are the same, and there is no return value and does not require the void keyword.
Call construction Method: Data type variable name = new construction Method (parameter value);
Call the Normal method: Object variable name. Method name (parameter value);
Second: Variable explanation
1. member variables (attributes) and scope
A member variable is a variable, also called an attribute, that is defined in a class body, outside of a method. The scope of a member variable is the entire class body.
2. Local variables and scopes
A local variable is a variable defined within a method body. The scope of a local variable is in the current method body.
Three: Method overloading
Overloaded (overload): In a class, there are two methods whose names are the same, but the parameter list is different. [Overloaded with constructor method]
Four: this keyword
Each non-static method of each class (not statically decorated) contains a This reference name, which points to the object that called the method.
1. Show the call member variable [method parameter name and member variable name simultaneously]
public class thistest{int x;int y; public void init (x, y) {this.x=x;this.y=y;}
public static void Main (String args[]) {thistest p = new Thistest (); P.init (4,3);}}
2. Show other constructor methods that call this class [used in the first row of the constructor method, you can display other constructor methods that call this class]
Java Fundamentals 1