java basic concepts of object-oriented

The basic concepts of object-oriented

Here we introduce some of the key concepts of object-oriented programming, and start using the class, you need to learn some terminology, we try to use relatively simple language to introduce, as these are more important, so I hope you take good understanding.

First, what is the object and object-oriented programming.

 

The object is the existence of a particular entity, with clearly defined state and behavior, is the core of object-oriented programming, is used to describe real-world entity, the entity providing the basis for computer applications, but also to complete a specific task package. So it is a bit wordy description of the object. Because the barrier with the traditional C language, C language is a procedural language, java language and object-oriented language, so the object is the core of java language.

That in the end what is the object, give me an example? In fact, in our lives, anything can become an abstract object, such as you have a car, the car is the object, and the object (the car), it has color, brand, with place of origin, etc., which we can also be called its properties, it can start to repair, etc. of these operations, we become its behavior. This is the subject.

In object-oriented programming (abbreviation: OOP), everything in the real world have all been treated as an object. OOP goal is a computer program to simulate the real-world concepts, we may be able to in a similar program using a computer simulation of real-world physical entity by the description of the object. OOP design and methods while also software system implementation.

Second, objects and classes

Class is a collection of objects with the same attributes and behavior. Class for each combination of objects and the operation of a mechanism common attributes.

Objects and classes have to do with it! We can give an example to answer this question. For example, there is now a cashier's called Zhang Xiaofang. Then we can put him abstraction becomes an object - an object cashier.

This object has some of the following information:

 

Name: Zhang Xiaofang

Title: Cashier

Age: 28

Weight: 60 kg

operating:

Receivables

Print invoice

Of course, a supermarket certainly more than a cashier, the cashier may Xiaoming, Xiaofang and so on. These are the cashiers object, or call examples, and all the cashiers have a name, title, age, weight and other attributes; print receipts and bills and other acts. We are through the cashier abstract objects, you can get a cashier class (class), this class has a name, title, age, weight and other attributes; print receipts and bills and other acts.

So we have come to: class is the prototype object, all objects of the same class have the same attributes and behavior, we abstract classes later, we can use the class definition entities. Class is a conceptual model, the object model is true.

Third, properties and methods

Java class is the basic unit of the class generally includes properties and methods.

Properties: properties represented in the class of things is variable, each attribute of each object has its unique value of the attribute name shared by all instances of the class, called attributes represent objects or entities have a characteristic in the class, For example, we mentioned above cashier class is to have the name, title, age, weight and other attributes, attribute describes the general use of the term.

Method: The method of operation of how to actually implement the specified operation target data performed in a manner the requested operation specification specifies how to do the operation in the algorithm object to perform the requested operation is called to obtain methods. For example, we said above class is to have the cashier receipts and print invoices and other methods, properties, general description of the use of verbs.

Fourth, the object-oriented thinking

Since object-oriented three simply summed up: a package (Encapsulation), inherited (Inheritance) and polymorphism (Polymorphism).

Package: some of the content is to seal it up, do not let others know. Some objects own internal implementation details are attributes of other objects did not want to know, then we can wrap it up. This is the basic concept of the package.

Inheritance: As the name suggests, is the son inherited his father's inheritance, subclasses and can also have a parent class in the class. Subclass inheritance of the parent class, but not all inherited inherited, if the child and parent class in the same package. Subclass inherits the parent class member method of all is not private (except construction method) is not a private member variables and inheritance, we will specifically about inheritance later re-introduction. The main goal of inherited reuse of code, saving development time.

Polymorphism: the same operation applied to different objects can have different interpretations, produce different execution result. At runtime, by the parent class pointer to invoke the method implemented in the subclass. In java polymorphic generally divided and overloaded methods override a method.

Compile-time polymorphism: compile-time polymorphism is achieved by overloading. For non-virtual member, the system at compile time, according to the transmission parameters, return type and other information decided what action to achieve.

Run-time polymorphism: run-time polymorphism refers until the system is running, before deciding what action to realize the actual situation. Compile-time polymorphism provides us with a fast operating speed features, and run-time polymorphism is to bring a highly flexible and abstract characteristics.

It allows us to understand these concepts is not possible, we can first look simple to understand and remember, later slowly digested.

Guess you like

Origin www.cnblogs.com/weibanggang/p/11184614.html