A brief introduction to Java three major features

Source: Internet
Author: User

1, object-oriented has three major characteristics, namely: encapsulation, inheritance and polymorphism.
2, Encapsulation: Object-oriented encapsulation is to describe the properties of an object and the behavior of the code encapsulated in a class, some properties are not intended to be public, or be accessed by other objects, so we use private to decorate the property, so that it is hidden; a method (decorated with public) is provided in the class. Commonly used is get, set method, you can manipulate these hidden properties, other classes can call these methods, change the value of hidden properties!
Encapsulation is to ensure that the software components have good modularity, the goal of the package is to achieve the "high cohesion, low coupling" software components, to prevent program interdependence and the impact of the changes. In object-oriented programming languages, objects are the most basic unit of encapsulation, and object-oriented encapsulation is clearer and more powerful than traditional language encapsulation.
3, inheritance: In the definition and implementation of a class, you can be on the basis of an existing class, using the extends keyword implementation of inheritance, subclasses can add a number of new content, or modify the original method to make it more suitable for special needs, which is inheritance. Inheritance is the mechanism by which subclasses automatically share the parent data and methods, which is a relationship between classes, which improves the reusability and extensibility of the software.
4, Polymorphic: Polymorphism is the use of the parent class at the time of declaration, the implementation or invocation of the use of specific subclasses, that is, do not modify the program code can be changed when the program is bound to run the specific code, so that the program can choose multiple running state, which is polymorphism, polymorphic enhanced software flexibility and extensibility. Here is an example, for example, when declaring an animal class, invoking a cat class (a subclass of an animal class), and actually performing a cat-eating method when the animal in the parent class is used.

A brief introduction to Java three major features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.