亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? chap07.htm

?? Thinking in Java, 2nd edition
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The main class <B>Shapes</B> contains a
<B>static</B> method <B>randShape(&#160;)</B> that produces a reference to a
randomly-selected <B>Shape</B> object each time you call it. Note that the
upcasting happens in each of the <B>return</B> statements, which take a
reference to a <B>Circle</B>, <B>Square</B>, or <B>Triangle</B> and sends it out
of the method as the return type, <B>Shape</B>. So whenever you call this method
you never get a chance to see what specific type it is, since you always get
back a plain <B>Shape</B> reference.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER7_I19' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER7_I20>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia"><B>main(&#160;)</B> contains an array of
<B>Shape</B> references filled through calls to <B>randShape(&#160;)</B>. At
this point you know you have <B>Shape</B>s, but you don&#8217;t know anything
more specific than that (and neither does the compiler). However, when you step
through this array and call <B>draw(&#160;)</B> for each one, the correct
type-specific behavior magically occurs, as you can see from one output
example:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE>Circle.draw()
Triangle.draw()
Circle.draw()
Circle.draw()
Circle.draw()
Square.draw()
Triangle.draw()
Square.draw()
Square.draw()</PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Of course, since the shapes are all
chosen randomly each time, your runs will have different results. The point of
choosing the shapes randomly is to drive home the understanding that the
compiler can have no special knowledge that allows it to make the correct calls
at compile-time. All the calls to <B>draw(&#160;)</B> are made through dynamic
binding.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER7_I20' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER7_I21>
</FONT><A NAME="_Toc375545332"></A><A NAME="_Toc481064630"></A><BR></P></DIV>
<A NAME="Heading240"></A><FONT FACE = "Verdana"><H3 ALIGN="LEFT">
Extensibility</H3></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Now let&#8217;s return to the musical
instrument example. Because of polymorphism, you can add as many new types as
you want to the system without changing the <B>tune(&#160;)</B> method. In a
well-designed OOP program, most or all of your methods will follow the model of
<B>tune(&#160;)</B> and communicate only with the base-class
interface<A NAME="Index691"></A><A NAME="Index692"></A>. Such a program is
<I>extensible<A NAME="Index693"></A></I> because you can add new functionality
by inheriting new data types from the common base class. The methods that
manipulate the base-class interface will not need to be changed at all to
accommodate the new classes.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER7_I21' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER7_I22>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Consider what happens if you take the
instrument example and add more methods in the base class and a number of new
classes. Here&#8217;s the diagram:</FONT><BR></P></DIV>
<DIV ALIGN="CENTER"><FONT FACE="Georgia"><IMG SRC="TIJ216.gif"></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">All these new classes work correctly with
the old, unchanged <B>tune(&#160;)</B> method. Even if <B>tune(&#160;)</B> is in
a separate file and new methods are added to the interface of <B>Instrument</B>,
<B>tune(&#160;)</B> works correctly without recompilation. Here is the
implementation of the above diagram:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE><font color=#009900>//: c07:music3:Music3.java</font>
<font color=#009900>// An extensible program.</font>
<font color=#0000ff>import</font> java.util.*;

<font color=#0000ff>class</font> Instrument {
  <font color=#0000ff>public</font> <font color=#0000ff>void</font> play() {
    System.out.println(<font color=#004488>"Instrument.play()"</font>);
  }
  <font color=#0000ff>public</font> String what() {
    <font color=#0000ff>return</font> <font color=#004488>"Instrument"</font>;
  }
  <font color=#0000ff>public</font> <font color=#0000ff>void</font> adjust() {}
}

<font color=#0000ff>class</font> Wind <font color=#0000ff>extends</font> Instrument {
  <font color=#0000ff>public</font> <font color=#0000ff>void</font> play() {
    System.out.println(<font color=#004488>"Wind.play()"</font>);
  }
  <font color=#0000ff>public</font> String what() { <font color=#0000ff>return</font> <font color=#004488>"Wind"</font>; }
  <font color=#0000ff>public</font> <font color=#0000ff>void</font> adjust() {}
}

<font color=#0000ff>class</font> Percussion <font color=#0000ff>extends</font> Instrument {
  <font color=#0000ff>public</font> <font color=#0000ff>void</font> play() {
    System.out.println(<font color=#004488>"Percussion.play()"</font>);
  }
  <font color=#0000ff>public</font> String what() { <font color=#0000ff>return</font> <font color=#004488>"Percussion"</font>; }
  <font color=#0000ff>public</font> <font color=#0000ff>void</font> adjust() {}
}

<font color=#0000ff>class</font> Stringed <font color=#0000ff>extends</font> Instrument {
  <font color=#0000ff>public</font> <font color=#0000ff>void</font> play() {
    System.out.println(<font color=#004488>"Stringed.play()"</font>);
  }
  <font color=#0000ff>public</font> String what() { <font color=#0000ff>return</font> <font color=#004488>"Stringed"</font>; }
  <font color=#0000ff>public</font> <font color=#0000ff>void</font> adjust() {}
}

<font color=#0000ff>class</font> Brass <font color=#0000ff>extends</font> Wind {
  <font color=#0000ff>public</font> <font color=#0000ff>void</font> play() {
    System.out.println(<font color=#004488>"Brass.play()"</font>);
  }
  <font color=#0000ff>public</font> <font color=#0000ff>void</font> adjust() {
    System.out.println(<font color=#004488>"Brass.adjust()"</font>);
  }
}

<font color=#0000ff>class</font> Woodwind <font color=#0000ff>extends</font> Wind {
  <font color=#0000ff>public</font> <font color=#0000ff>void</font> play() {
    System.out.println(<font color=#004488>"Woodwind.play()"</font>);
  }
  <font color=#0000ff>public</font> String what() { <font color=#0000ff>return</font> <font color=#004488>"Woodwind"</font>; }
}

<font color=#0000ff>public</font> <font color=#0000ff>class</font> Music3 {
  <font color=#009900>// Doesn't care about type, so new types</font>
  <font color=#009900>// added to the system still work right:</font>
  <font color=#0000ff>static</font> <font color=#0000ff>void</font> tune(Instrument i) {
    <font color=#009900>// ...</font>
    i.play();
  }
  <font color=#0000ff>static</font> <font color=#0000ff>void</font> tuneAll(Instrument[] e) {
    <font color=#0000ff>for</font>(<font color=#0000ff>int</font> i = 0; i &lt; e.length; i++)
      tune(e[i]);
  }
  <font color=#0000ff>public</font> <font color=#0000ff>static</font> <font color=#0000ff>void</font> main(String[] args) {
    Instrument[] orchestra = <font color=#0000ff>new</font> Instrument[5];
    <font color=#0000ff>int</font> i = 0;
    <font color=#009900>// Upcasting during addition to the array:</font>
    orchestra[i++] = <font color=#0000ff>new</font> Wind();
    orchestra[i++] = <font color=#0000ff>new</font> Percussion();
    orchestra[i++] = <font color=#0000ff>new</font> Stringed();
    orchestra[i++] = <font color=#0000ff>new</font> Brass();
    orchestra[i++] = <font color=#0000ff>new</font> Woodwind();
    tuneAll(orchestra);
  }
} <font color=#009900>///:~</font></PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The new methods are <B>what(&#160;)</B>,
which returns a <B>String</B> reference with a description of the class, and
<B>adjust(&#160;)</B>, which provides some way to adjust each instrument.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER7_I22' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER7_I23>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">In <B>main(&#160;)</B>, when you place
something inside the <B>Instrument </B>array you automatically upcast to
<B>Instrument</B>. 
</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER7_I23' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER7_I24>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">You can see that the <B>tune(&#160;)</B>
method is blissfully ignorant of all the code changes that have happened around
it, and yet it works correctly. This is exactly what polymorphism is supposed to
provide. Your code changes don&#8217;t cause damage to parts of the program that
should not be affected. Put another way, polymorphism is one of the most
important techniques that allow the programmer to &#8220;separate the things
that change from the things that stay the same.&#8221;

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER7_I24' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER7_I25>
</FONT><A NAME="_Toc375545333"></A><A NAME="_Toc481064631"></A><BR></P></DIV>
<A NAME="Heading241"></A><FONT FACE = "Verdana"><H2 ALIGN="LEFT">
Overriding vs.
overloading<BR><A NAME="Index694"></A><A NAME="Index695"></A></H2></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Let&#8217;s take a different look at the
first example in this chapter. In the following program, the interface of the
method <B>play(&#160;)</B> is changed in the process of overriding it, which
means that you haven&#8217;t <I>overridden</I> the method, but instead
<I>overloaded </I>it. The compiler allows you to overload methods so it gives no
complaint. But the behavior is probably not what you want. Here&#8217;s the
example:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE><font color=#009900>//: c07:WindError.java </font>
<font color=#009900>// Accidentally changing the interface.</font>

<font color=#0000ff>class</font> NoteX {
  <font color=#0000ff>public</font> <font color=#0000ff>static</font> <font color=#0000ff>final</font> <font color=#0000ff>int</font>
    MIDDLE_C = 0, C_SHARP = 1, C_FLAT = 2;
}

<font color=#0000ff>class</font> InstrumentX {
  <font color=#0000ff>public</font> <font color=#0000ff>void</font> play(<font color=#0000ff>int</font> NoteX) {
    System.out.println(<font color=#004488>"InstrumentX.play()"</font>);
  }
}

<font color=#0000ff>class</font> WindX <font color=#0000ff>extends</font> InstrumentX {
  <font color=#009900>// OOPS! Changes the method interface:</font>
  <font color=#0000ff>public</font> <font color=#0000ff>void</font> play(NoteX n) {
    System.out.println(<font color=#004488>"WindX.play(NoteX n)"</font>);
  }
}

<font color=#0000ff>public</font> <font color=#0000ff>class</font> WindError {
  <font color=#0000ff>public</font> <font color=#0000ff>static</font> <font color=#0000ff>void</font> tune(InstrumentX i) {
    <font color=#009900>// ...</font>
    i.play(NoteX.MIDDLE_C);
  }
  <font color=#0000ff>public</font> <font color=#0000ff>static</font> <font color=#0000ff>void</font> main(String[] args) {
    WindX flute = <font color=#0000ff>new</font> WindX();
    tune(flute); <font color=#009900>// Not the desired behavior!</font>
  }
} <font color=#009900>///:~</font></PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">There&#8217;s another confusing aspect
thrown in here. In <B>InstrumentX</B>, the <B>play(&#160;)</B> method takes an
<B>int</B> that has the identifier <B>NoteX</B>. That is, even though
<B>NoteX</B> is a class name, it can also be used as an identifier without
complaint. But in <B>WindX</B>, <B>play(&#160;)</B> takes a <B>NoteX</B>
reference that has an identifier <B>n.</B> (Although you could even say
<B>play(NoteX NoteX)</B> without an error.) Thus it appears that the programmer
intended to override <B>play(&#160;)</B> but mistyped the method a bit. The
compiler, however, assumed that an overload and not an override was intended.
Note that if you follow the standard Java naming convention, the argument
identifier would be <B>noteX</B> (lowercase &#8216;n&#8217;), which would
distinguish it from the class name.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER7_I25' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER7_I26>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">In <B>tune</B>, the <B>InstrumentX</B>
<B>i</B> is sent the <B>play(&#160;)</B> message, with one of
<B>NoteX</B>&#8217;s members (<B>MIDDLE_C</B>) as an argument. Since
<B>NoteX</B> contains <B>int</B> definitions, this means that the <B>int</B>
version of the now-overloaded <B>play(&#160;)</B> method is called, and since
that has <I>not</I> been overridden the base-class version is used.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER7_I26' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品你懂的| 国产a区久久久| 欧美色综合天天久久综合精品| 久久久久久一二三区| 久久精品国产77777蜜臀| 欧美日韩国产经典色站一区二区三区| 中文字幕在线不卡一区| 风间由美一区二区av101| 国产无人区一区二区三区| 国产成人在线视频免费播放| 久久久五月婷婷| 成人激情文学综合网| 亚洲国产电影在线观看| 成人小视频免费观看| 中文在线免费一区三区高中清不卡| 国产综合久久久久久久久久久久| 2024国产精品| 国产不卡视频在线观看| 国产精品色呦呦| 一本一道久久a久久精品综合蜜臀| 日韩伦理av电影| 在线不卡欧美精品一区二区三区| 免费的成人av| 国产欧美日韩在线看| 成人精品小蝌蚪| 亚洲精品亚洲人成人网| av成人免费在线观看| 亚洲一二三四久久| 欧美精品电影在线播放| 国产高清在线精品| **性色生活片久久毛片| 欧美伊人精品成人久久综合97| 亚洲午夜在线电影| 久久这里只有精品视频网| 一本色道亚洲精品aⅴ| 国产在线精品免费| 亚洲尤物在线视频观看| 久久精品视频网| 欧美一区二区三区系列电影| 不卡av电影在线播放| 麻豆一区二区三| 亚洲午夜三级在线| 18成人在线视频| 国产日韩欧美在线一区| 7777精品伊人久久久大香线蕉的 | 久久九九99视频| 欧美色图12p| 91在线云播放| 国产成人精品免费网站| 男女性色大片免费观看一区二区| 亚洲私人影院在线观看| 国产欧美久久久精品影院| 91精品国产一区二区三区| 欧美在线观看视频一区二区| 99国内精品久久| 粉嫩久久99精品久久久久久夜| 九九九久久久精品| 久久69国产一区二区蜜臀 | 免费观看在线色综合| 亚洲一二三四在线观看| 亚洲激情自拍偷拍| 亚洲欧美乱综合| 亚洲色图.com| 亚洲同性gay激情无套| 国产精品久久久久一区| 国产精品情趣视频| 中文字幕日韩av资源站| 国产精品久线在线观看| 国产精品国产三级国产a| 欧美国产日韩a欧美在线观看| 精品国产乱码久久久久久浪潮| 日韩一区二区电影在线| 91精品婷婷国产综合久久性色 | 精品一区二区三区久久久| 日本亚洲最大的色成网站www| 亚洲国产精品综合小说图片区| 亚洲男人的天堂在线aⅴ视频| 国产精品三级av| 一区二区三区四区高清精品免费观看 | 亚洲精品大片www| 亚洲国产精品久久一线不卡| 亚洲国产成人av好男人在线观看| 亚洲国产综合人成综合网站| 亚洲第一在线综合网站| 日本在线不卡一区| 国产综合色视频| 国产精品一区二区男女羞羞无遮挡| 国产成人鲁色资源国产91色综 | 欧美视频在线一区| 欧美日韩一区二区三区四区| 91精品婷婷国产综合久久| 欧美电视剧在线看免费| 国产日韩欧美麻豆| 综合分类小说区另类春色亚洲小说欧美 | 91免费国产在线观看| 欧美午夜电影网| 精品国产免费人成电影在线观看四季 | 欧美精品久久久久久久多人混战 | 久久免费偷拍视频| 自拍偷拍国产亚洲| 首页亚洲欧美制服丝腿| 国产一区二区三区最好精华液| 成人自拍视频在线| 欧美色欧美亚洲另类二区| 日韩精品一区二区三区四区 | 日韩一区二区在线观看| 国产日产精品一区| 一区二区三区四区高清精品免费观看 | 日韩午夜av一区| 欧美激情一区二区三区不卡| 一区二区三区精品在线| 污片在线观看一区二区| 国产精品 欧美精品| 欧美日韩精品是欧美日韩精品| 欧美mv和日韩mv国产网站| 成人免费一区二区三区视频 | 亚洲男人的天堂av| 免费观看在线综合色| 9久草视频在线视频精品| 欧美一区二区三区喷汁尤物| 中文字幕免费在线观看视频一区| 天涯成人国产亚洲精品一区av| 国产精品一二三四| 欧美日韩精品一区二区三区 | 91精品国产黑色紧身裤美女| 日本韩国欧美三级| 国产九九视频一区二区三区| 久久天堂av综合合色蜜桃网| 国产精品久久久99| 美女在线视频一区| 一本大道久久a久久综合| 久久天天做天天爱综合色| 亚洲成人自拍一区| 99久久777色| 久久精品亚洲精品国产欧美| 丝袜美腿亚洲综合| 成人动漫中文字幕| 2021中文字幕一区亚洲| 丝袜诱惑制服诱惑色一区在线观看| 国产精品综合久久| 日韩一级精品视频在线观看| 一区二区三区不卡在线观看| 国产**成人网毛片九色| 欧美sm美女调教| 天天操天天综合网| 欧美性xxxxx极品少妇| 最新高清无码专区| yourporn久久国产精品| 国产日韩视频一区二区三区| 久久精品国产77777蜜臀| 91精品国产综合久久久蜜臀粉嫩 | 日韩成人一级大片| 欧美日韩国产片| 亚洲国产wwwccc36天堂| 在线亚洲人成电影网站色www| 国产精品久久久久久久久图文区 | 中文一区一区三区高中清不卡| 精品午夜一区二区三区在线观看| 69p69国产精品| 午夜精品一区在线观看| 欧美日韩精品免费| 亚洲伊人伊色伊影伊综合网| 欧美在线一二三四区| 亚洲激情成人在线| 色噜噜久久综合| 亚洲一级二级三级| 精品视频在线视频| 午夜精品久久久久久久久久久 | 热久久国产精品| 欧美精品少妇一区二区三区| 午夜精品久久久久久久久| 在线播放91灌醉迷j高跟美女 | 精品一区二区三区在线播放视频| 欧美一区二区三区免费| 精品一区二区三区影院在线午夜| 欧美精品成人一区二区三区四区| 日韩电影免费一区| 久久免费美女视频| 成人app网站| 18欧美亚洲精品| 欧美亚洲综合色| 日本成人在线一区| 久久日韩精品一区二区五区| 国产精品正在播放| 亚洲天堂中文字幕| 欧美日韩国产不卡| 久久99精品国产.久久久久久| 久久蜜桃av一区二区天堂| 成人免费毛片a| 亚洲乱码国产乱码精品精小说| 欧美在线999| 久久99国内精品| 国产精品白丝在线| 欧美三级视频在线| 久久97超碰国产精品超碰| 国产精品久线观看视频| 欧美日本一区二区三区四区| 美女一区二区三区在线观看| 国产日韩欧美a| 欧美日韩一二三区|