Java up and down transformation

Source: Internet
Author: User

Recently in the Java programming thought, before the Java can only be considered fur, probably see the seventh chapter inherited a noun-upward transformation. So we will discuss the content and meaning of the downward and upward transformation, and the content can be updated with the progress of my reading.

Upward transformation

  According to the idea of Java programming, "Providing methods for a new class" is not the most important aspect of inheritance technology, the most important thing is to show the relationship between the new class and the base class. Overview for the new class is a type of an existing class.

Patch the code on the book, slightly change

classinstrument{//Parent Class     Public voidplay () {}; Static voidTune (instrument i) {i.play (); System.out.println (i.ToString ()+ ". Play ()"); }} Public classWindextendsinstrument{//subclass Inherits Parent class     Public Static voidMain (string[] args) {wind flute=NewWind ();    Instrument.tune (flute); }}

Output:

[Email protected] ()

Note that Instrument.tune (flute) calls a wind reference, at which point the exported class is converted to a base class.

Specific meaning personal understanding such as the code above, the parent class instrument already has the tune method, but the parent class tune method calls the Instrument object. If the subclass wind wants to use the tune method needs to rewrite the tune, but the upward transformation eliminates the hassle.

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.