Java encapsulation, inheritance, polymorphism

Source: Internet
Author: User

Encapsulation: Hides some information about a class inside a class, does not allow external programs to access directly, but instead uses the methods provided by the class to manipulate hidden information

1. Modify the visibility of the properties of the class and restrict it by private;

2. Perform the appropriate action on the property by the specified method

Inheritance: Inheritance in Java is a single inheritance, inheriting the properties and methods of the parent class (the base class), and can override the parent class method in the subclass (derived class);

Polymorphism: Inheritance is the basis for polymorphism

1. The object of the parent class can point to a reference to the parent class;

2. The object of the parent class can point to a reference to the subclass;

3. The object of the subclass cannot point to a reference to the parent class;

4. The polymorphism of the method is to invoke the method of the different subclasses to execute the corresponding class method, the method of the class is preferred to execute, in the case of the absence of this class in the parent class to find;

5. Subclasses can have different expressive forms, animals (dogs, cats, Fox);

Java encapsulation, inheritance, polymorphism

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.