The development of the program has undergone two main stages: process oriented, object oriented. Object-oriented is the mainstream of current software development.
Process-oriented is to analyze the steps required to solve the problem, and then use the function to implement these steps step-by-step, using the time one by one call.
Object-oriented is the decomposition of the transaction constituting the problem into individual objects. The object is not built to complete a step but to describe the behavior of something throughout the problem-solving step.
Object-oriented is to focus on the application of encapsulation, inheritance, polymorphism and other design methods. Object-oriented design is an object-oriented implementation of the symbolic design system, which is constructed as a "real-world" object using a method that is very close to the actual domain terminology.
Object-oriented has three main features: encapsulation, inheritance, polymorphism.
Encapsulation: not visible to external. The encapsulation mechanism is to ensure that the external property values are not arbitrarily changed and the function methods are called arbitrarily by combining the variables describing the properties of the object with the method of implementing the object's function.
Inheritance: Extends the functionality of the class. The inheritance mechanism greatly enhances the reusability of the program code, improves the efficiency of software development, reduces the possibility of errors in the program, and facilitates the modification of the program.
Polymorphism: Includes overloading of methods, polymorphism of objects. Polymorphism allows the application of the same name phenomenon, so that the degree of abstraction and introduction of the program is higher, to help the development of the Group collaborative development work smoothly.
design of classes and objects
Class: A description, abstract, or conceptual definition of a certain class of things.
Object: is the actual existence of each individual of such a thing, and thus also known as an instance (instance).
A class is made up of properties and methods.
In a Java source file you can create multiple classes, but the main class can only have one, the main class is identified with public, the main class must contain the main () method, and the name of the main class must remain exactly the same as the Java source file name.
You can create multiple objects in a class.
(1) Definition and creation of the class. The definition format for the class is as follows:
Class Name { //definition class name data type attribute 1; Define the properties in the class, format the "Access Rights property data type property name;" ...... Data type attribute n;
Defines a method in a class, the format "access rights method returns a value data type method name ()"public return value of the data type method name (parameter 1, parameter 2, ..., parameter n) { program statement; [return expression;] }}
(2) Creation and use of objects. Object Creation Format one:
Class name nullNew class name (); Instantiating an Object
Object Creation Format two:
Class name newnew person (); //Create an object of the person class per and instantiate.
(3) Accessing properties or methods in an object
The properties or method formats in the Access object are as follows:
Access attribute: object name. Property name Access Method: object name. Method Name ()
For example:
Per.name = ' Zhang San '; Assigns a value to the Name property of the per object of the person class
Per.age = 12; assigns a value to the age property of the per object of the person class
Pre.print (); the print () method that invokes the per object of the person class
(4) Anonymous object. An anonymous object is an object that is not explicitly given a name, and is typically used only once. For example
New Person (). print (); //Anonymous object to invoke the print () method of the person class
Java-three major features of object-oriented (encapsulation, inheritance, polymorphism)