Knowledge Point Grooming 2

Source: Internet
Author: User

This week, I studied several basic features of object-oriented.

Inheritance, encapsulation, polymorphism and abstraction are the four basic features of object-oriented programming.

Encapsulation hides the internal implementation mechanism of the class, provides the get and set methods without affecting the user's use, alters the internal structure of the class, and thus protects the data.

Inheritance is when a subclass automatically acquires all the information of the parent class at creation time, and the subclass can extend on its basis, and inheritance fully improves the reusability of the code.

Polymorphism is the embodiment of the same behavior, different objects.

Polymorphism is also divided into static polymorphism and dynamic polymorphism.

Static polymorphism refers to the method that the program can determine its invocation at compile time, also known as the compile-time polymorphism, the more direct static polymorphic implementation is the method of overloading.

Polymorphic polymorphism refers to the object that the program refers to in the operation of the system polymorphism determination method, also known as run-time polymorphism, which is realized by overriding the same name method in the parent class, and then determining it according to the object instantiation.

Polymorphism in the concept of upward and downward transformation, the upward transformation is a security must be achieved. In order to improve security in the downward transition, we usually use instanceof first to determine.

To summarize, the so-called polymorphic is to use a reference to the parent class to the subclass object, in Java all ordinary methods are polymorphic bindings by default, declaring final can avoid the overhead of polymorphic binding performance, so that the JVM does not have to look for and directly execute.

We use abstract to declare an abstract class, forcing subclasses to rewrite their abstract methods, as well as inheriting non-abstract methods for subclasses, without instantiation or instantiation, so that the code is both reusable and can implement polymorphism through the parent class, but does not need to write the method body in the parent class.

The so-called interface, which is characterized by all methods are abstract methods, and the abstract class is different, the interface can support multi-inheritance multi-implementation, the interface does not contain constructors, the interface can not include instance member variables, but may have declared as static and final variables.

Knowledge Point Grooming 2

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.