From this point on, I will start to get in touch with the very important part of Java learning-object-oriented programming, and, of course, first and foremost to understand a few important concepts, although they are all textual, but also need everyone and I can understand.
It is said that the early program design experienced the "problem-oriented", "process-oriented" stage, with the development of computer technology, as well as the complexity of the problem to improve, the previous procedures have not been designed to meet the needs of this development. So, starting from the 1970s, there have been a variety of object-oriented programming languages, the following is the development of computer language process:
First, the object
Object-oriented programming is to apply the thought method commonly used in the process of understanding the world to the program design. Objects are things that exist in the real world, they are tangible, such as a person, an object, and so on.
The characteristics of the object are divided into static and dynamic features. Static characteristics refer to the appearance, nature and properties of the object, and dynamic characteristics refer to the function and behavior of the object. Objective things are complex, but people always from a certain point of view, using the ability of abstract analysis, from a number of features to extract the most representative, the most reflective of the nature of the characteristics of the object to be studied in detail. People abstract the static characteristics of objects into attributes, which are described by data, are called variables in the Java language, and people abstract the dynamic characteristics of objects into behaviors, which are represented by a set of code, and the operation of the data is called a method in the Java language. An object consists of a set of properties and a set of methods that manipulate the property.
Second, class
A set of objects that have the same properties and the same behavior is called a class. Broadly speaking, a set of things of a common nature is called a class.
Class is an abstract concept, in order to solve the problem by means of a class, you must create an instantiated class object with a class, and then access the class's member variables through the class object to invoke the class's member methods to implement the function of the program. This is like the "car" itself is an abstract concept, only the use of a specific car, to feel the function of the car. A class can create multiple class objects that have the same property pattern, but can have different property values. The Java program opens up memory space for each class object to hold its own property values.
Object-oriented programming has three main features, as follows:
? Encapsulation of
? Inheritance of
? Polymorphism
1) Encapsulation
Encapsulation is an important principle that an object-oriented approach should follow. It has two meanings: one refers to the object's attributes and behavior as an inseparable whole, the two "encapsulated" in an indivisible independent unit (i.e. object). Another layer of meaning refers to "information concealment", hiding information that does not need to be known to the outside world, the properties and behaviors of some objects allow the outside user to know or use, but not allow the change, while other properties or behaviors are not allowed to be known to the outside world, or only allow the use of the function of the object, and as far as possible
Encapsulation mechanism in the program design, the description of the object attributes of the variables and methods to implement the object function together, defined as a program unit, and to ensure that the outside world can not arbitrarily change the value of its internal properties, and can not arbitrarily mobilize its internal function methods.
Another feature of the encapsulation mechanism is that different levels of "visibility" or access rights are specified for variables and methods encapsulated within a whole.
2) Inheritance
First, you have classes that reflect the general nature of things, and then derive a class that reflects a particular thing based on it. such as the existing car class, the class describes the general properties and behavior of cars, further produce sedan class, Sedan class is inherited from the car class, Sedan class not only has all the properties and behavior of the car class, but also to increase the characteristics and behavior of cars.
In Java programming, the existing classes can be the Java Development environment provides a batch of the most basic program-class library. User-developed program classes are inherited from these existing classes. In this way, the properties and behaviors described by the class now, that is, defined variables and methods, are fully available in the class in which the inheritance is generated. An inherited class is called a parent or superclass, and a class that inherits from it is called a subclass or derived class. Based on the inheritance mechanism, the derived class inherits all the members of the superclass and adds some of its own new members accordingly.
If a subclass is allowed to inherit only one parent class, it is called single inheritance, and if more than one parent class is allowed, it is called multiple inheritance. Many object-oriented programming languages currently do not support multiple inheritance. The Java language uses interfaces (interface) to compensate for the fact that subclasses that do not support multiple inheritance in Java cannot enjoy the imperfections of members of more than one parent class.
3) Polymorphism
Polymorphism is another important feature of object-oriented programming. Polymorphism is a phenomenon that allows duplicate names in programs. The Java language contains method overloads and members covering two forms of polymorphism.
Method overloading: In a class, multiple methods are allowed to use the same name, but the parameters of the method are different and the functions are done differently. Member overrides: Subclasses and parent classes allow the same variable name, but different data types allow the same method name, but complete functionality is different.
The polymorphic characteristics make the program more abstract and simple, which helps the program designer to develop the program in a collaborative way.
You learn Java--------Object-oriented programming (thread)