Home  >  Article  >  Java  >  java what is object oriented

java what is object oriented

little bottle
little bottleOriginal
2019-05-20 13:53:3333070browse

Java object-oriented refers to simulating concepts in the real world in computer programs, and using similar entities in computer programs to simulate entities in the real world with the help of object descriptions.

java what is object oriented

#What are objects and object-oriented programming?

Objects are specific entities that exist, with clearly defined states and behaviors. They are the core of object-oriented programming. They are used to describe entities in the real world, provide an entity basis for computer applications, and are also a way to complete specific tasks. Encapsulation. It's a bit long-winded to describe the object like this. Because it is different from the traditional C language, C language is a procedural language, and Java language is an object-oriented language, so objects are the core of Java language.

So what exactly is an object? Can you give an example? In fact, in our lives, everything can be abstracted into an object. For example, if you have a car, this car is the object. This object (car) has a color, a brand, a place of origin, etc. We can also call these things Its properties, it can also operate, need to be repaired, etc., we become its behavior. This is the object.

In object-oriented programming (abbreviation: OOP), all things in the real world are regarded as objects. The goal of OOP is to simulate concepts in the real world in computer programs. We can use similar entities to simulate entities in the real world in computer programs with the help of object descriptions. At the same time, OOP is also a method for designing and implementing software systems.

Object-oriented thinking

Because object-oriented thinking can be simply summarized into three: Encapsulation, Inheritance and Polymorphism.

Encapsulation: It is to seal certain content so that others cannot know it. Some objects have internal implementation details of their own attributes that we don't want other objects to know, so we can encapsulate them. This is the basic concept of encapsulation.

Inheritance: As the name suggests, inheritance is the inheritance of a son from his father. A class can also have subclasses and parent classes. The subclass inherits from the parent class, but inheritance is not all inherited if the subclass and the parent class are in the same package. The subclass inherits all non-private member methods (except constructors) and non-private member variables in the parent class. We will introduce the details of inheritance later. The goal of inheritance is to reuse code and save development time.

Polymorphism: The same operation acts on different objects and can have different interpretations and produce different execution results. At runtime, methods in the implemented subclass can be called through a pointer to the parent class. Polymorphism in Java is generally divided into method rewriting and method overloading.

Compile-time polymorphism: Compile-time polymorphism is achieved through overloading. For non-virtual members, the system determines what operation to implement based on the parameters passed, the type returned, and other information during compilation.

Runtime polymorphism: Runtime polymorphism means that it is not until the system is running that the operation is decided based on the actual situation. Compile-time polymorphism provides us with fast running speed, while run-time polymorphism brings high flexibility and abstraction.

Related learning recommendations: java basics

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

Statement:
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