DAY14 Polymorphism and abstraction

Source: Internet
Author: User

Polymorphism: The same behavior, different implementations.

Polymorphism is divided into: static polymorphism and dynamic polymorphism.

Static polymorphism: The implementation and effect of the method is determined at compile time. --using overloads to implement

Dynamic polymorphism: The implementation and performance of the method can be determined after running. --using dynamic binding and overriding implementations

Dynamic binding Technology: Reference data type conversions, instanceof keywords

Reference data type conversion: Transformation up: The reference to the parent class is directed to the object of the child class.

Downward transformation: After running, it is true that this class of references point to this class of objects or to the subclass object in order to succeed.

instanceof Keyword: Used to determine the true type of a run-time object and to determine whether an object is an instance of a class. Returns TRUE/FALSE.

Usage: Object instanceof class name

Polymorphic applications: polymorphic parameters: That is, when a method's formal parameter is a reference, any object that is compatible with the reference can be passed to the method.

Polymorphic Collection: is a collection of different data types. Example: object[]

Abstraction (abstract):

When the abstract modification method, the method is an abstract method, the expression class has this method, the implementation of the method is completed by subclasses.

When abstract modifies a class, the class is an abstract class, and an abstract class cannot produce an object.

Note: 1. Classes with abstract methods must be abstract classes

2. Abstract classes may not have abstract methods (syntax allowed)

3, abstract class in addition to using abstract modification, and other similar to ordinary classes, attributes, constructs (for subclasses), the method has been implemented and so on.

4. Subclasses must override all the abstract methods of the parent class when inheriting the abstract class, otherwise this class is also an abstract class.

Comparison of abstract and final modified classes:

Abstract design Parent class, cannot produce object, can inherit.

Final design End class, cannot be inherited, can produce objects.

DAY14 Polymorphism and abstraction

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.