The process-oriented thought is only the verb, the object-oriented thought is the noun + verb
Refrigerator. Open
Refrigerators-Storage
Refrigerator. Close
The method of noun refinement
Object-oriented three features: encapsulation, inheritance, polymorphism
(*) class and object relationships
Class: Description of a Thing (attribute, behavior) (member variable, member method)
Objects: Things entities (values, specific practices)
/*
(*) (*) There is no string keyword in Java, and string is a string class
(*) (*) char[] and string mutual transfer:
*/
Object. Object member
Each new is generated with a fresh object and space is allocated in the heap memory
(*) member variables and local variables
A member variable acts on the entire class, and the local variable acts in the function, or in a statement.
The member variable is in heap memory and exists in memory because the object exists. Local variables exist in the stack memory.
Anonymous Objects :
How to use one: when a member variable or method of an object is called only once, it can be done with an anonymous object, which is easier to write
Use method Two: You can pass an anonymous object as an actual parameter----------as shown in
(*) encapsulation : Refers to the properties of hidden objects and implementation details, only provide public access to external.
Benefits-Isolate changes, ease of use, improve reusability, and improve security.
Principle-hides content that does not need to be provided externally, hides attributes, and provides access to public methods.
The function is the smallest package, the class is also encapsulated, the package is also encapsulated, and the framework is encapsulated.
Access modifier:Private class member can not be called by object
(*) Private is only a form of representation of the package
(*) constructor : The process of new is to call the class's constructor, allocate the heap memory space, assign the initial value to the member variable, no assignment is the default value
When a constructor is not defined in a class, the system defaults to a constructor that adds an empty argument to the class.
When a constructor is defined in the system, the system does not default to an empty parameter constructor.
(*)new , (person p = New person (s), "abc") means a new person type space in the heap memory, and assigns the parameter value in () to the corresponding member variable. () No parameter is the assignment of the default value.
The constructor runs only once at new time
constructing blocks of code : Initialize the object with more uniform properties, precedence over constructor execution
(*)this- keyword: This is the object (instance) that invokes the object (instance) of the method. Represents the reference to the object to which the function belongs.
Mutual calls between constructors with This,this () need to be in the first row
Java Self-study note (fifth day) object-oriented--char[] and string--Package--constructor--this