Understanding of Java Object Oriented Programming

1. We always say that java is an object-oriented programming language, so what is object-oriented?

I understand it this way, the object is the entity of the existence of things, such as pigs, dogs, flowers, etc. are all objects, and the object is composed of two parts. The three major characteristics of object-oriented programming: inheritance, polymorphism, class is the carrier that encapsulates the attributes and behaviors of objects, and conversely, a class of entities with the same attributes and behaviors is called a class.

2. How is object orientation implemented in java?

(1 ) Through classes: A class is a carrier that encapsulates the attributes and behaviors of objects, and conversely, a class of entities with the same attributes and behaviors is called a class.

(2 ) Encapsulation: It is the core idea of ​​object-oriented programming, which encapsulates the attributes and behaviors of objects, and the carrier that encapsulates the attributes and behaviors of objects is the class. The class usually hides its implementation details from customers, which is the idea of ​​encapsulation , users can only access data through externally provided interfaces.

(3 ) Polymorphism: It means that objects of different classes are allowed to respond to the same message, and different methods are called according to the different instances of object creation. The essence is that the behavior of the object is determined at compile time and runtime.

There are two knowledge points here:

Static dispatch, method overloading, compile-time decision

Dynamic dispatch, method overriding, runtime decision.

The characteristics of polymorphism: replaceability, flexibility, extensibility, unified coding style.

(4 ) Inheritance: Inheritance refers to deriving a new class from an existing class. The new class can absorb the data attributes and behaviors of the existing class, and can extend new functions.

Features: Scalability, code reuse.

The difference between abstract class and interface: abstract class single inheritance, can declare and implement, maximum application scenarios, design of template method pattern.

Interface: multiple inheritance, only declaration, interface-oriented programming, spring .

Object-oriented goals: code repeatability, scalability, reliability.

 

Article source: http://blog.csdn.net/u012316953/article/details/52739027

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325733983&siteId=291194637