In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what are the concepts and characteristics of Java object-oriented". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Preface
Object-oriented is referred to as OO (Object Oriented). In the later stage, new system development methods such as object-oriented Analysis (OOA), object-oriented Design (OOD) and object-oriented programming (OOP) have emerged.
For the Java language, everything is the object. Each object represents a specific operation. Objects that can be independently or inherited from other places are combined to form a complete program design. The information is transmitted between objects through interaction, so as to realize program development.
What is the object?
Java is an object-oriented programming language, and the core of its programming is object. Object is a real entity, each object corresponds to an entity, on the contrary, every entity in reality is an object, it is a more specific concept.
Characteristics of the object:
1. Objects have properties and behaviors.
two。 The object has a changing state.
3. The object is unique.
4. Objects are instances of a category.
5. Everything is an object, and everything in the real world can be regarded as an object.
For example, in real-world schools, there will be entities such as students and teachers, students have attributes such as student numbers, names, classes (data), and students also have operations such as learning, asking questions, eating and walking. Students are just abstract descriptions, and this abstract description is called "class". In the school activities are individual students, that is, Zhang, Li and so on. These specific individuals are called "objects", and "objects" are also called "examples".
Three core features of object-oriented
Object-oriented development mode is helpful for people to open up their thinking, facilitate the division of programs in the specific development process, facilitate programmers to divide work and cooperation, and improve development efficiency. Object-oriented programming has the following advantages.
1. Reusability: code reuse, reduce the amount of code, improve development efficiency. The three core object-oriented features (inheritance, encapsulation, and polymorphism) described below all revolve around this core.
two。 Scalability: means that new functions can be easily added to the system to facilitate software modification.
3. Manageability: the ability to combine functions with data for easy management.
Object-oriented has three core features: inheritance, encapsulation and polymorphism.
Inheritance
To put it simply, it is like that in reality, children inherit all the property owned by their parents, but the inheritance in the program means that the subclass has all the characteristics and behavior of the parent class, which is a relationship between classes. Java only supports single inheritance.
For a Chinese teacher class and a math teacher class, if inheritance is not used, the properties and methods that need to be defined in the two classes are as follows:
We can see that many attributes and methods in the Chinese teacher class and the mathematics teacher class are the same. These same attributes and methods can be extracted and placed in a parent class, which is used to be inherited by the Chinese teacher class and the mathematics teacher class. Of course, the parent class can also inherit other classes. As shown below:
The characteristics of summary inheritance can be represented by the following tree diagram:
The main staff of the school is a large category, teachers and students are two subcategories of the main personnel of the school, and teachers can be divided into two subcategories: Chinese teachers and math teachers, and students can also be divided into two subcategories: monitor and group leader.
The purpose of using this hierarchical classification is to extract the common properties and methods of multiple classes and put them in their parent classes, and then only need to define their own unique properties and methods in the subclasses. and get their common properties and methods in the parent class in the form of inheritance.
Encapsulation property
Encapsulation is a programming mechanism that binds code and the data it processes, which ensures that programs and data are free from external interference and misuse. The purpose of encapsulation is to protect information. He has the following advantages:
1. Protects the information in the class, which prevents externally defined code from accessing internal code and data at will.
two。 Hide the details, some information that does not need to be modified and used by programmers, such as the keyboard in the cash machine, the user only needs to know which key to press to achieve what operation, as for its internal operation, the user does not need to know.
3. It is helpful to establish the loose coupling relationship between each system and improve the independence of the system. When the implementation of a system changes, as long as its interface remains unchanged, it will not affect the use of other systems. For example, no matter how the storage mode of the U disk is changed, as long as the USB interface on the U disk remains unchanged, it will not affect the normal operation of the user.
4. Improve the reuse rate of software and reduce the cost. Each system is a relatively independent whole and can be used in different environments. For example, a U disk can be used on multiple computers.
The basic encapsulation unit of the Java language is the class. Because the purpose of a class is to encapsulate complexity, there is a mechanism to hide implementation complexity within the class. Java provides private and public access modes, the public interface of the class represents everything that external users should or can know, and private method data can only be accessed through the member code of the class, which ensures that things you don't want to see don't happen.
Polymorphisms
Object-oriented polymorphism, that is, "one interface, multiple methods". Polymorphism is reflected in that the properties and methods defined in the parent class can have different properties or expressions after they are inherited by the subclass. Polymorphism allows an interface to be used by more than one kind, which makes up for the deficiency of single inheritance.
This is the end of the introduction of "what are the concepts and characteristics of Java object-oriented". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.