One. Overview of methods for classes
1. What is the method of the class
The method of the class is a function module, which acts as "doing one thing"
Class method: A kind of common behavior of Things is the method of class.
2. How to define a class method
The method of a class must include the following three parts:
The name of the method
The return value type of the method
The body of the method
Public return value type method name () {
The body of the method
}
3. Method invocation
This process is called a method call in a program by using the method name to execute the statements contained in the method.
There are two forms of method invocation:
Methods in the same class, call the method directly using the method name.
Different classes of methods, first create the object, and then use the "Object name. Method Name" to invoke
4. Common errors
There is no way to define a return value type, there can be no return statement.
A method cannot have more than one return value and can have at most one
Multiple methods cannot be nested with each other, that is, methods can no longer be defined in methods.
Second, the object-oriented advantages:
1. Consistent with human thinking
2. Information hiding, improve the maintainability and security of the program
3. Improve the reusability of the program.
Object-Oriented Programming thinking:
The method of a class can implement a specific function, and other classes do not need to know how it is implemented! Knowing the class that implements this function and its method name can be called directly without repeating the encoding.
Jen Baby Java Basic notes