1. Anonymous objects
- Anonymous object: An object without a name
- Application Scenario: Call the method, only once, the anonymous object can be passed as the actual parameter
?? Example: New Student (). name;2. Encapsulation (private)
- Encapsulation Overview: Refers to the properties of hidden objects and implementation details, only provide public access to external
- Benefits: Hides the implementation details to provide public access, improves code reusability, and improves security
- Principle: Hide content that does not need to be provided externally. Hides the property and provides a public way to access it.
- Private keyword Features
?? A. Permission modifiers
?? B. member variables and member methods can be decorated
?? C. Members whose modifications are only accessible in this class
- Private application
?? (1) The member variable is modified with private;
?? (2) provide the corresponding getxxx () and Setxxx () methods. 3.this keywordsFunction: When our local variables and member variables are the same, if this is not used, the problem of the local variable hidden member variable is caused.
Feature: The reference object of the current class;
4. Construction method
- Overview
?? Role: Create an object, initialize it to a member of the object
?? Features: A. The method name is the same as the class name;
???? B. No return value type, not even void
???? C. No specific return value
- Overloading Considerations for construction methods
?? (1) If the construction method is not given, the system will automatically provide a non-parametric construction method;
?? (2) If the construction method is given, the system will no longer provide a default parameterless construction method (it is recommended to always give a non-parametric construction method).
- Two ways to assign a value to a member variable
?? Setxxx () method
?? Construction method
Anonymous object, encapsulation (private), this keyword, construction method