Object-oriented programming idea is the core idea of Java, so Java must learn to understand what object-oriented programming, understanding the process is long, in After learning the basics of Java to realize this idea is certainly thorough!
First, the object-oriented thinking
Process-oriented and object-oriented programming are two different ideas. java object oriented C language procedure is oriented. Prime Minister, we have to understand how the difference between the two ideas.
For example: man elephant put into the refrigerator
Process for: opening the refrigerator 1 to 3 into two elephant closing the door
Object-oriented:
people{
Open (refrigerator) {refrigerator, open ()}
Operation (Elephant) {Elephant proceeds (refrigerator)}
Close (refrigerator) {refrigerator, SCO ()}
}
Elephant{
Entering (refrigerator) {}
}
refrigerator{
turn on(){}
Close up(){}
}
Personal understanding: the entire event there are three objects: humans, elephants, refrigerator
Have a respective operation of each object (i.e., method), properties
An object attribute analysis operates as the center, to complete the operation of the process.
Second, objects, classes
- Object : The object is the actual existence of this kind of things for each individual object is an instance of a class ( object is not to find a girlfriend ), have state and behavior. For example, a dog is an object that states are: color, name, breed; behavior: wagging its tail, called, eat and so on.
- Class : Class is a class of things described, is an abstract definition of the concept.
For example: define a class Dog, that contains attributes and actions of the dog. You can create new objects by a Dog xg
public class Dog {// Create a class
String breed;
int age ;
String color;
void barking(){
}
void hungry(){
}
void sleeping(){
}
}
Dog xg = new Dog (); // create an object
Class composition :
Properties: class member variable corresponding to
Behavior: The members of the corresponding category
Note: Everything Is an Object