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