First, object-oriented
Teacher's Day approaching, a group of students summoned a blackboard, how to complete it? For a child, you tell him: "We want to determine the blackboard theme, clearly the gist of content, search specific content, layout ideas, drawing and writing, arrange logistical assistance." He might froze in place, I do not know the it measures. But you just have to give every child said, "You want to make water, wash rag, when Xiao Ming a mistake, he put a wet rag to clean the blackboard." ....... When we determine to be a blackboard schoolchildren What people, everyone just needs to do what, and with whom, to whom do the blackboard will be able to complete this matter.
Java is an object-oriented programming language: the problem transaction into individual objects, each object has to determine how state and behavior in problem-solving process, build relationships, solve common or description of the transaction. In short, create an object, describe the state and behavior, resolve or describe things through mutual relations.
Object: a specific entity, a specific thing.
Second, the class
Class: an Object "class" have the same characteristics and behavior.
The role of class: as a template with a particular feature or behavior, the use of bulk.
Method → → behavior characteristic properties
Class is created:
Keywords: class
Format: public class name of the class {}
Class property definitions:
Format: public property type name;
The method of the class definition:
Format: public method return type method name (parameter type parameter name, ......) {
The method body
}
(Common types: int Integer, String string)
note:
- is public access can be modified.
- Between different parameters, separated.
- The method requires the use of external conditions: method parameters. It may be an object.
- When the method does not return a value, with void. void is a command, the method returns no value.
- The method requires the use of their property, write directly attribute name; other classes of property xx, xx property name (xx for the other classes in the class name).
Three, Java objects in
Objects created:
Keywords: new
Format: class name = new class name object name ();
Use properties of the object:
Format: Object Name property name;
The method of using an object:
Format: Method name object name (parameter value, ......);