Home Java javaTutorial How to understand java object-oriented

How to understand java object-oriented

May 29, 2019 pm 02:50 PM

How to understand java object-oriented

How to understand Java object-oriented?

Java is an object-oriented programming language. Accurately understand the orientation of Java. Only with objects can you master JAVA programming ideas and methods better and faster. This article introduces Java object-oriented to you to help you better understand Java.

1. What is an object?

First of all, let me explain that the object is not Java. In fact, it is just a concept and a program used to solve problems. Design thinking methods. To understand objects, you must combine them with object-oriented. In object-oriented, a class is formed after abstracting the common attributes and behaviors of a certain type of things. A practical example of a class is called an object. So it can be seen from the above that there is such a relationship between classes and objects: a class is the abstraction of a group of objects with common attribute names and behaviors, and an object is a real example of a class.

A class is the reflection of entities in the real world or the thinking world in the computer. It encapsulates data and operations on these data.

The class describes a collection of objects with the same characteristics (data elements, state variables) and behavior (operations on data elements, state variables). If I need a tool with certain functions, then I can customize this class to contain the data I need, as well as the functions provided by this class.

Objects are variables with class type. Classes and objects are basic concepts in object-oriented programming technology. A class is an abstraction of an object, and an object is a concrete instance of a class. Classes are abstract and do not occupy memory, while objects are concrete and occupy storage space. A class is a blueprint for creating objects, a software template that defines the methods and variables included in an object of a specific type.

JAVA is an object-oriented programming language. Objects are abstracted from classes. All problems are handled through objects. Objects can operate the properties and methods of classes to solve problems. Therefore, it is very necessary to understand the creation, operation and death of objects. An object can be thought of as abstracting a special case from a class of things. This special case is used to deal with problems that arise in this type of thing. In the Java language, objects are created through the new operator.

2. Objects and object references

The following expression: A a1 = new A; It means that A is a class, a1 is a reference, and a1 is not an object , new A is the object, and the a1 reference points to the new A object.

In JAVA, "=" cannot be regarded as an assignment statement. It is not assigning one object to another object. Its execution process essentially passes the address of the object on the right to the left The reference makes the reference on the left point to the object on the right. JAVA does not appear to have pointers on the surface, but its reference is essentially a pointer. What is stored in the reference is not the object, but the address of the object, making the reference point to the object. In JAVA, the "=" statement should not be translated into an assignment statement, because what it performs is indeed not an assignment process, but a process of transmitting an address. Being translated into an assignment statement will cause many misunderstandings and the translation is inaccurate. .

Another example: A a2; It represents that A is a class, a2 is a reference, a2 is not an object, and the object pointed by a2 is empty null;

Another example: a2 = a1; It represents , a2 is a reference, a1 is also a reference, the address of the object pointed by a1 is passed to a2 (address transfer), so that a2 and a1 point to the same object.

To sum up, it can be simply recorded as, during initialization, the left side of the "=" statement is a reference, and the new one on the right side is the object.

When the following "=" statements are referenced on the left and right, the left and right references simultaneously point to the object pointed to by the right reference. The so-called instance is actually a synonym for object.

3. Java Inheritance Analysis

Inheritance is a significant feature of object-oriented. Inheritance is the derivation of a new class from an existing class. The new class can absorb the data attributes and behaviors of the existing class, and can expand new capabilities. Java inheritance is a technology that uses the definition of an existing class as a basis to create a new class. The definition of a new class can add new data or new functions, or use the functions of the parent class, but it cannot selectively inherit the parent class. This technology makes it very easy to reuse previous code, which can greatly shorten the development cycle and reduce development costs.

Inheritance is a cornerstone of Java object-oriented programming technology because it allows the creation of hierarchical classes. Inheritance can be understood as the process by which one object obtains properties from another object. If class A is the parent class of class B, and class B is the parent class of class C, we also say that C is a subclass of A, and class C inherits from class A. In Java, class inheritance is single inheritance, that is, a subclass can only have one parent class. The two keywords often used in inheritance are extends (IS-A, what is it) and implements (Has-A, what function does it have). The use of these two keywords determines whether one object has an IS-A relationship with another object.



The above is the detailed content of How to understand java object-oriented. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

How to simplify field mapping issues in system docking using MapStruct? How to simplify field mapping issues in system docking using MapStruct? Apr 19, 2025 pm 06:21 PM

Field mapping processing in system docking often encounters a difficult problem when performing system docking: how to effectively map the interface fields of system A...

How to elegantly obtain entity class variable names to build database query conditions? How to elegantly obtain entity class variable names to build database query conditions? Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

How do I convert names to numbers to implement sorting and maintain consistency in groups? How do I convert names to numbers to implement sorting and maintain consistency in groups? Apr 19, 2025 pm 11:30 PM

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How to safely convert Java objects to arrays? How to safely convert Java objects to arrays? Apr 19, 2025 pm 11:33 PM

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? Apr 19, 2025 pm 11:27 PM

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to elegantly get entity class variable name building query conditions when using TKMyBatis for database query? How to elegantly get entity class variable name building query conditions when using TKMyBatis for database query? Apr 19, 2025 pm 09:51 PM

When using TKMyBatis for database queries, how to gracefully get entity class variable names to build query conditions is a common problem. This article will pin...

See all articles