What are the three major features of java?

⭐Column introduction

This column will continue to update various questions about JAVA, including interview questions, JAVA introduction to proficiency, etc.

The update speed is maintained at 3-5 articles per day
Insert image description here

Problem Description

What are the three major features of java?

Insert image description here

Answer

1. JAVA has three major features: encapsulation, inheritance and polymorphism.
2. Encapsulation: Object-oriented encapsulation is to encapsulate the code describing the properties and behavior of an object in a class. Some properties are not expected to be made public or accessed by other objects, so we use private to modify the property so that It is hidden; the class provides methods (modified with public), commonly used are get and set methods, which can operate these hidden attributes. Other classes can change the value of the hidden attributes by calling these methods!

Encapsulation is the basis for ensuring that software components have excellent modularity. The goal of encapsulation is to achieve "high cohesion and low coupling" of software components and prevent the impact of changes caused by program interdependence. In object-oriented programming languages, objects are the most basic unit of encapsulation. Object-oriented encapsulation is clearer and more powerful than encapsulation in traditional languages.
3. Inheritance: When defining and implementing a class, you can do it on the basis of an existing class and use the extends keyword to achieve inheritance; you can add some new content to the subclass, or modify the original method to make it More suitable for special needs, this is inheritance. Inheritance is a mechanism for subclasses to automatically share parent class data and methods. This is a relationship between classes that improves the reusability and scalability of software.
4. Polymorphism: Polymorphism means using the parent class when declaring and using specific subclasses when implementing or calling; that is, you can change the specific code bound to the program when it is running without modifying the program code, allowing the program to select multiple Running state, this is polymorphism. Polymorphism enhances the flexibility and scalability of software. Here is an example. For example, when declaring, the animal class is used, and when calling, an object of the cat class (a subclass of the animal class) is passed. When the animal-eating method in the parent class is executed, what is actually executed is Cats - How to eat.

Guess you like

Origin blog.csdn.net/weixin_50843918/article/details/132999315