Detailed explanation of object-oriented programming ideas and object examples in Java language

When beginners learn Java, object-oriented is difficult to understand, so today Xiaobian will put this idea for you to understand in a very simple way. First, let's briefly explain the idea of object-oriented.

object-oriented:

The official language is very abstract. We put aside the official interpretation and definition. Think about what you have, right!! We have a series of organs such as hands, feet, eyes, mouth and nose. To take their own organs as our attributes, whether they can be happy, angry, sad, laughing and scolding, whether these are our behaviors, then their own attributes plus their own behaviors are called an object.

be careful!! We ourselves, an individual is an object, because you are you and I am me. Although we have the same, we are different. For example, you are taller than me and I have longer hair than you.

The next step is further. You and I are human, because I have something similar to you, so you and I belong to human beings. Human is the general name of human, and it is also an abstraction of similar objects.

From the above, you and I are just two special columns of human beings, but aliens can also call us human beings. We can see that the specific expression or instance of a class is an object, and the abstraction or general generalization of an object is a class.

What Xiaobian said is so simple that we don't use examples. Let's use java code to reflect the situation.

Next, let's write a person's class. Note: objects come from classes. Classes first, objects later, and class instantiation only.

The original code is not appropriate, and the minor edition is modified as follows:

Operation results:

The above is the object-oriented understanding.

Class:

The above Xiaobian has said that a class is an attribute plus behavior, and the above code has explained the attribute

In order to better illustrate the behavior, we add the behavior method of class in Java

After the class has a method, the object can also call this method. We say that at this time, the object has some behavior embodiment of the class.

Obviously, the result of the operation must be:

Let's talk about some features of classes:

Class, he has his own things and things for the object. A class is a member of a class

Class members generally include initialization blocks, constructors, attributes, methods, internal classes and enumeration classes.

If it belongs to a class (it can be called directly with class name and member), it is called with static.

In fact, all objects of a class can be used, whether static or not, but those that do not need static modification are objects that can only be called by instantiated objects.

Needless to say about objects, just remember two points. To create objects, you must call the constructor.

The initialization block can be regarded as a special constructor without parameters. When creating an object, it will be called anyway.

summary

The above is all about the detailed explanation of Java language object-oriented programming ideas and object examples. I hope it will be helpful to you. Interested friends can refer to: detailed explanation of the accommodation examples of Java programming thought objects, Java enterprise project development ideas, etc. if you have any questions, you can leave a message at any time. Xiaobian will reply to you in time. Thank you for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>