Day Sixth: Object-oriented first day
1: What is the difference between a process and an object-oriented?
1.1: Process-oriented thinking, the entire process users need to participate. But object-oriented, the user only calls some other people's functions, as to how these features are implemented, the user does not need to know.
Example: Need: Put the lunch box in the refrigerator.
Process oriented:
1: I open the refrigerator.
2: Put the Lunchbox in
3: I close the refrigerator.
Object-oriented:
1: First analyze some of the requirements of the number of objects: refrigerators, lunch boxes.
2: What property or behavior the object has. : Refrigerator: Open, off.
3: What is the relationship between objects
1: I call the refrigerator to open the function.
2: I put the lunch box in.
3: Call off the function of the refrigerator.
My opinion: Process-oriented is contained in object-oriented, but the process is encapsulated in a method
2: Object-oriented Analysis process
2.1: First analyze what objects are in the requirements.
2.2: What property or behavior the object has.
2.3: What does an object have to do with an object?
3: What is the object? What is a class?
Class: A kind, which is an abstraction of multiple objects. (for example, a car's design drawing is a class, can not see the physical)
Object: The concrete thing of the class. All things in the world are objects. A class is an abstraction of an object that is a concrete thing of a class. (The car is designed to be an object, to see the physical)
4:
4.1: Describe a suspect.
Age: 20 or so, Height: 170-175. Gender: Male, face: Square, Accent: Sichuan accent. Stature: thin. Lefty. : Features
Walking: Inside eight. Behavior
Lock an object: characteristics and behavior.
4.2: Definition of the class.
4.3: How to access the properties and objects of an object
Access object's properties: Object name. Properties
Methods for accessing objects: Object names. Method Name ()
4.4: Construction method.
4.1: Syntax for constructing methods.
1: The method name is the same as the class name.
2: no return value. The return value type is not written.
4.2: Why should there be a construction method? What is the function of the construction method?
Function: Initializes the properties of the object. The object must be created before it can be called.
4.3: How does the construction method differ from the normal method on the call?
The constructor method can only be called when the object is created, and cannot be called after. This means that it can only be called when new.
If a class does not have a write constructor, it automatically adds an argument-free construction method. If you write a construction method, you will not add a construction method for long. As long as it is a class, there must be a construction method.
Summarize:
1: Object-oriented Analysis process.
1.1 Analyze what the requirements are
1.2 Analyzing the properties of each object
1.3 Analyzing what is the connection between each object
2: Create Write a class
Class name
3: How to create an object
Create with the new constructor
4: How to access the properties and methods of the object.
Objects. Properties, objects. Methods
5: The definition of the construction method and how it differs from the normal method: Method name, return value, function, call on.
Constructors have the same method name and type, no return value, and are used as initialization object properties and can only be invoked with the new keyword.
6: Overloading of constructor methods: overloading of methods.
Parameter list is different
7: The difference between a member variable and a local variable.
Tomorrow:
1: Memory analysis.
2: Delivery of basic data type parameters and reference data type parameters.
3:this and encapsulation.
1 /*Requirement: There is a person's left hand is a red peach A, the right hand put the square piece K, asked to2 the contents of the left and right hand exchange. Object-oriented thinking to consider. */3 class Person4 {5 String Lhand;6 String Rhand;7 8 String temp;9 Ten voidChange () { Onetemp =Lhand; ALhand =Rhand; -Rhand =temp; - } the } - - - classTest01 + { - Public Static voidMain (string[] args) + { APerson p =NewPerson (); at -P.lhand = "A"; -P.rhand = "K"; - -System.out.println ("Left hand:" +p.lhand+ ", right hand:" +P.rhand); - P.change (); inSystem.out.println ("Left hand:" +p.lhand+ ", right hand:" +P.rhand); - } to}View Code
Day Sixth: Object-oriented first day