Introduction to Java from getting started to giving up: object-oriented concepts (Entry edition ),
To know what object orientation is, you must first have an object ·
Okay, we are joking. We need to explain what object orientation is.
Example:
"Silly, what did you eat for breakfast today ?"
Silly: "You can eat a lot of food. There are two slices of bread, a chicken pie, a few dishes and leaves, a little salad dressing, and a cup of cola and a bag of fried potato chips"
Dumb: "silly, you have no more than four! Do you say that the chicken Fort package you eat is not good --"
Silly: "Hey, okay, this chicken hamburger package I eat"
OK. From the above example, you can understand what object orientation is. Beginners can understand this as follows: encapsulate a lot of separate data and methods together and it becomes an object.
Later, we will explain some object-oriented concepts: Class, object, attribute, method, encapsulation, inheritance, and polymorphism. Through these concepts, we can understand what object orientation is.
How many objects are displayed in the above example?
First: Chicken hamburger package: contains chicken hamburger, fries, cola
Second: chicken burger: contains the attributes of bread, chicken bread, lettuce, and Hula sauce.
Third: a bag of chips: contains many chips, a packaging bag
Fourth: A Cup Of Cola: A cup, ice cubes, cola
Fifth :......
Did you find that this analysis can be endless ??? Haha, that's right. This is Object-Oriented Programming analysis.
Of course, in actual development, we will not continue to break down this way, and there is no need to break down an object into atoms.
In general, we will analyze specific objects based on functions. If some objects have the same attributes and methods, we will classify them into one class. The specific analysis is what we will do next.
Basic Concepts
I. Category:
Class is an abstraction of a group of objects with the same attributes and methods. Simply put, it is a concept. For example, "goddess" is a class.
Goddess
Ii. objects:
An object is an instance of a class. Simply put, it is a real object. It is a specific thing. For example, some goddesses are very specific.
Sister Lin cangjing
Jia dajie
Iii. attributes:
Attributes are the characteristics of objects and are nouns. For example, all the goddesses above have height, weight, name, age, and measurements ·
Lin Jie: 173, 54, Lin Zhiling, 43 and confidential.
Cangjing elder sister: 155, 45 kg, cangjing Kong, 34 and confidential.
Jia dajie: 166 cm, confidential, Jia Ling, 35 and confidential.
Iv. Method:
A method is the action of an object. It is a verb or a verb.
Sister Lin has methods such as swimming, running, and advertising.
Sister Cang has photo and film methods.
Jia dajie has some methods such as playing sketch and singing.
5. encapsulation:
Encapsulation is easy to understand. You have sent and received packages. This is an encapsulation.
The biggest advantage of encapsulation is to hide details. It is okay to reserve only the functional APIs that users are interested in.
For example, from the user's point of view, we only care about the use of the following functions: On, off, heating, cooling, temperature adjustment, etc. We don't need to care about how these functions are implemented, what the corresponding electronic circuit diagram is, and what type of circuit board is used.
Vi. Inheritance:
The inheritance should be easy to understand, that is, the son of long shenglong, Feng Shengfeng, And the mouse will make holes. If this happens, ask Old Wang next door.
7. Polymorphism:
Polymorphism in Object-Oriented means that different objects have different execution effects on the same commands. For example, if you want different huluwa to execute the "zoom in ()" method, the corresponding effect will be different.
Let's introduce the basic concepts first today. Next time, let's look at the Java syntax corresponding to these concepts.
"Software thinking" blog address:51CTO,BlogInterested friends can visit other related blog posts.