The multi-state interface of JAVA oo key content

Source: Internet
Author: User

The four basic features of inheriting encapsulated polymorphic abstraction in JAVA Oo and being named Object-oriented programming

Encapsulation hides the internal implementation mechanism of the class so that it can change the internal structure of the class without affecting the user's premise , while protecting the data

Inheritance is to reuse the parent class code

Polymorphism refers to the ability of an object to have multiple forms. Subclasses of a class can define their unique behavior while sharing some of the same characteristics of the parent class.

In particular, polymorphism can be understood as:

1. The first is that different methods of the object can use the same method name, which is the concept of overloading. (overloading refers to the same method name in a class that has the same parameter list)

2. The same object performs the corresponding behavior according to different messages, or it can be thought that sending a message to an object allows the object to choose the appropriate behavior

So polymorphism can be divided into static polymorphic and dynamic polymorphic

In layman's terms: static polymorphism means that you can decide which method to call when the system calls the method and the dynamic method needs to be judged when the user instantiates it.

Here's how the polymorphic implementation works:

Use dynamic binding and override mechanisms in Java to implement polymorphic

The default dynamic binding in Java so-called dynamic binding means that for a method defined in a parent class, if the method is overridden in a subclass, a reference to the parent class type is called to the subclass's method, which is dynamic binding

In general, methods implemented and defined in subclasses cannot be called in a parent class, and methods that are only defined in the parent class and implemented are called in the subclass.

For a multi-state summary:

1. Using a reference to the parent class type to point to the object of the child class

2. The reference can only call methods defined in the parent class and cannot invoke methods unique to the subclass

3. If a method in the parent class is overridden in a subclass, the method in the subclass is called when the method is called

4. In polymorphism, subclasses can call all methods in the parent class

The multi-state interface of JAVA oo key content

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.