Java up and down transformation

Source: Internet
Author: User

1) The Subclass object reference is transformed into a reference to the parent class, called upward transformation. According to the current understanding, an important role of upward transformation is to facilitate the implementation of polymorphism, in the process of upward transformation, relative to the parent class, the subclass of redundant methods are lost, that is, access is not. However, it can be accessed by a downward transformation.

2) The parent class object reference is converted to a subclass reference, called downward transformation. Before using a downward transformation, it is better to use a instanceof B to determine if a is really an example of B (subclass), and then change it down again, or you will run out of the transition failure exception.

Reference: http://www.cnblogs.com/wuyuegb2312/p/java-cast.html

Java up and down transformation

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.