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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? chap07.htm

?? Thinking in Java, 2nd edition
?? HTM
?? 第 1 頁 / 共 5 頁
字號:

<backtalk:display ID=TIJ3_CHAPTER7_I27>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The output is:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE>InstrumentX.play()</PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">This certainly doesn&#8217;t appear to be
a polymorphic method call. Once you understand what&#8217;s happening, you can
fix the problem fairly easily, but imagine how difficult it might be to find the
bug if it&#8217;s buried in a program of significant size.

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

<backtalk:display ID=TIJ3_CHAPTER7_I28>
</FONT><A NAME="_Toc375545334"></A><A NAME="_Toc481064632"></A><BR></P></DIV>
<A NAME="Heading242"></A><FONT FACE = "Verdana"><H2 ALIGN="LEFT">
Abstract classes <BR>and methods</H2></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">In all the instrument examples, the
methods in the base class <B>Instrument</B> were always &#8220;dummy&#8221;
methods. If these methods are ever called, you&#8217;ve done something wrong.
That&#8217;s because the intent of <B>Instrument</B> is to create a <I>common
interface</I> for all the classes derived from it.

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

<backtalk:display ID=TIJ3_CHAPTER7_I29>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The only reason to establish this common
interface<A NAME="Index696"></A><A NAME="Index697"></A> is so it can be
expressed differently for each different subtype. It establishes a basic form,
so you can say what&#8217;s in common with all the derived classes. Another way
of saying this is to call <B>Instrument</B> an <I>abstract base class</I>
<A NAME="Index698"></A><A NAME="Index699"></A><A NAME="Index700"></A>(or simply
an <I>abstract class</I>). You create an abstract class when you want to
manipulate a set of classes through this common interface. All derived-class
methods that match the signature of the base-class declaration will be called
using the dynamic binding mechanism. (However, as seen in the last section, if
the method&#8217;s name is the same as the base class but the arguments are
different, you&#8217;ve got overloading, which probably isn&#8217;t what you
want.) 
</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER7_I29' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER7_I30>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">If you have an abstract class like
<B>Instrument</B>, objects of that class almost always have no meaning. That is,
<B>Instrument</B> is meant to express only the interface, and not a particular
implementation, so creating an <B>Instrument</B> object makes no sense, and
you&#8217;ll probably want to prevent the user from doing it. This can be
accomplished by making all the methods in <B>Instrument</B> print error
messages, but that delays the information until run-time and requires reliable
exhaustive testing on the user&#8217;s part. It&#8217;s always better to catch
problems at compile-time. 
</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER7_I30' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER7_I31>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Java provides a mechanism for doing this
called the <I>abstract
method</I></FONT><A NAME="fnB37" HREF="#fn37">[37]</A><FONT FACE="Georgia">.
This is a method that is incomplete; it has only a declaration and no method
body. Here is the syntax for an abstract method declaration:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE><font color=#0000ff>abstract</font> <font color=#0000ff>void</font> f();</PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">A class containing abstract methods is
called an <I>abstract class</I>. If a class contains one or more abstract
methods, the class must be qualified as <B>abstract</B>. (Otherwise, the
compiler gives you an error message.)

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

<backtalk:display ID=TIJ3_CHAPTER7_I32>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">If an abstract class is incomplete, what
is the compiler supposed to do when someone tries to make an object of that
class? It cannot safely create an object of an abstract class, so you get an
error message from the compiler. This way the compiler ensures the purity of the
abstract class, and you don&#8217;t need to worry about misusing it.

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

<backtalk:display ID=TIJ3_CHAPTER7_I33>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">If you
<A NAME="Index701"></A><A NAME="Index702"></A><A NAME="Index703"></A>inherit
from an abstract class and you want to make objects of the new type, you must
provide method definitions for all the abstract methods in the base class. If
you don&#8217;t (and you may choose not to), then the derived class is also
abstract and the compiler will force you to qualify <I>that</I> class with the
<A NAME="Index704"></A><B>abstract</B> keyword.

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

<backtalk:display ID=TIJ3_CHAPTER7_I34>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">It&#8217;s possible to create a class as
<B>abstract</B> without including any <B>abstract</B> methods. This is useful
when you&#8217;ve got a class in which it doesn&#8217;t make sense to have any
<B>abstract</B> methods, and yet you want to prevent any instances of that
class. 
</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER7_I34' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_CHAPTER7_I35>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The <B>Instrument</B> class can easily be
turned into an <B>abstract</B> class. Only some of the methods will be
<B>abstract</B>, since making a class abstract doesn&#8217;t force you to make
all the methods <B>abstract</B>.<B> </B>Here&#8217;s what it looks
like:</FONT><BR></P></DIV>
<DIV ALIGN="CENTER"><FONT FACE="Georgia"><IMG SRC="TIJ217.gif"></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Here&#8217;s the orchestra example
modified to use <B>abstract</B> classes and methods:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE><font color=#009900>//: c07:music4:Music4.java</font>
<font color=#009900>// Abstract classes and methods.</font>
<font color=#0000ff>import</font> java.util.*;

<font color=#0000ff>abstract</font> <font color=#0000ff>class</font> Instrument {
  <font color=#0000ff>int</font> i; <font color=#009900>// storage allocated for each</font>
  <font color=#0000ff>public</font> <font color=#0000ff>abstract</font> <font color=#0000ff>void</font> play();
  <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>abstract</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> Music4 {
  <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">You can see that there&#8217;s really no
change except in the base class.

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

<backtalk:display ID=TIJ3_CHAPTER7_I36>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">It&#8217;s helpful to create <B>abstract
</B>classes and methods because they make the abstractness of a class explicit,
and tell both the user and the compiler how it was
int<A NAME="_Toc375545338"></A>ended to be used.

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

<backtalk:display ID=TIJ3_CHAPTER7_I37>
</FONT><A NAME="_Toc481064633"></A><BR></P></DIV>
<A NAME="Heading243"></A><FONT FACE = "Verdana"><H2 ALIGN="LEFT">
Constructors and polymorphism</H2></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">As usual,
<A NAME="Index705"></A><A NAME="Index706"></A>constructors are different from
other kinds of methods. This is also true when polymorphism is involved. Even
though constructors are not polymorphic (although you can have a kind of
&#8220;virtual constructor,&#8221; as you will see in Chapter 12), it&#8217;s
important to understand the way constructors work in complex hierarchies and
with polymorphism. This understanding will help you avoid unpleasant
entanglements.

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

<backtalk:display ID=TIJ3_CHAPTER7_I38>
</FONT><A NAME="_Toc375545339"></A><A NAME="_Toc481064634"></A><BR></P></DIV>
<A NAME="Heading244"></A><FONT FACE = "Verdana"><H3 ALIGN="LEFT">
Order of constructor
calls<BR><A NAME="Index707"></A><A NAME="Index708"></A></H3></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The order of constructor calls was
briefly discussed in Chapter 4 and again in Chapter 6, but that was before
polymorphism was introduced. 

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

<backtalk:display ID=TIJ3_CHAPTER7_I39>
</FONT><BR></P></DIV>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美精品一卡二卡| 日本精品视频一区二区三区| 欧美一区二区三区思思人| 亚洲成a人v欧美综合天堂| 欧美二区乱c少妇| 国产综合色精品一区二区三区| 精品盗摄一区二区三区| 国产精品自拍三区| 亚洲丝袜另类动漫二区| 欧洲国内综合视频| 久久精品国产99久久6| 欧美激情中文不卡| 欧美午夜一区二区三区免费大片| 视频一区二区三区在线| wwwwxxxxx欧美| 91浏览器入口在线观看| 日本亚洲三级在线| 中文字幕一区二区日韩精品绯色 | 日韩电影免费一区| 久久亚洲捆绑美女| 色偷偷久久一区二区三区| 丝袜美腿成人在线| 久久久久久影视| 在线日韩国产精品| 国产精品亚洲一区二区三区妖精| 亚洲色图色小说| 日韩女优电影在线观看| 成人av网站免费观看| 日韩国产欧美三级| 国产精品久久一卡二卡| 欧美精品乱码久久久久久| 国产成人小视频| 午夜精品123| 中文字幕免费在线观看视频一区| 欧美日韩国产天堂| 国产91精品在线观看| 午夜精品福利在线| 国产精品白丝在线| 精品国产乱码久久久久久1区2区| 色吧成人激情小说| 国产精品一区在线观看你懂的| 亚洲一区成人在线| 国产精品每日更新在线播放网址 | 久久综合色播五月| 欧美专区日韩专区| 成人黄色av电影| 九九热在线视频观看这里只有精品| 亚洲精品综合在线| 国产精品三级电影| 久久综合九色综合97_久久久| 精品视频一区二区三区免费| 91丝袜美腿高跟国产极品老师| 韩国三级中文字幕hd久久精品| 亚洲成人av电影| 一区二区三区精密机械公司| 国产精品视频线看| 国产日韩欧美精品电影三级在线| 日韩亚洲欧美在线| 欧美日韩国产欧美日美国产精品| 99麻豆久久久国产精品免费优播| 国产一二精品视频| 韩国v欧美v日本v亚洲v| 狂野欧美性猛交blacked| 亚洲高清三级视频| 午夜精品在线看| 日韩在线观看一区二区| 偷窥国产亚洲免费视频| 天天色综合成人网| 天堂在线一区二区| 日韩国产高清在线| 免费视频最近日韩| 卡一卡二国产精品 | 久国产精品韩国三级视频| 三级在线观看一区二区| 午夜精品成人在线| 丝袜国产日韩另类美女| 青青草一区二区三区| 轻轻草成人在线| 麻豆精品国产传媒mv男同| 九九久久精品视频| 国产成人在线观看| 成人福利视频在线看| a美女胸又www黄视频久久| 99免费精品在线观看| 91视视频在线直接观看在线看网页在线看| 成人丝袜18视频在线观看| 成人aaaa免费全部观看| 91一区在线观看| 欧美日韩一区二区三区不卡| 在线播放亚洲一区| 精品久久久久一区| 久久久777精品电影网影网| 中文字幕高清不卡| 亚洲乱码中文字幕| 午夜一区二区三区在线观看| 日本不卡一区二区| 国产麻豆视频精品| 一本一道综合狠狠老| 91精品国模一区二区三区| www久久精品| 亚洲欧美国产77777| 日日夜夜精品视频免费| 国产一区二区中文字幕| 成人午夜精品一区二区三区| 欧洲激情一区二区| 精品免费日韩av| 亚洲女同一区二区| 秋霞国产午夜精品免费视频| 成人免费毛片嘿嘿连载视频| 欧美在线啊v一区| 26uuu精品一区二区| 亚洲欧美偷拍三级| 国内精品免费在线观看| 色综合视频一区二区三区高清| 欧美电影一区二区三区| 国产日韩高清在线| 丝袜亚洲另类欧美| 不卡av免费在线观看| 6080午夜不卡| 国产精品国产精品国产专区不片| 日韩黄色小视频| 99国产麻豆精品| 久久欧美中文字幕| 亚洲成人激情av| 丁香婷婷综合激情五月色| 4438亚洲最大| 亚洲天堂免费在线观看视频| 日本视频在线一区| 99久久久精品| 久久久精品tv| 美女www一区二区| 欧美私人免费视频| 18成人在线视频| 国产一区二区h| 日韩亚洲欧美在线观看| 亚洲一区二区中文在线| eeuss鲁片一区二区三区在线看| 欧美一级生活片| 亚洲国产成人高清精品| 91丨porny丨蝌蚪视频| 欧美精品一区二区高清在线观看| 亚洲妇熟xx妇色黄| 91首页免费视频| 日韩一区中文字幕| 国产精品综合在线视频| 欧美成人免费网站| 日本中文一区二区三区| 欧美日本在线播放| 一区二区三国产精华液| 97se亚洲国产综合自在线观| 中文字幕成人网| 国产精品18久久久| 亚洲精品在线免费观看视频| 免费人成在线不卡| 91精品福利在线一区二区三区| 一区二区三区日韩精品视频| 成人av电影免费观看| 国产欧美一区二区三区沐欲| 国产制服丝袜一区| 久久亚洲综合色一区二区三区| 麻豆精品视频在线观看视频| 日韩免费电影一区| 精品一二线国产| 欧美精品一区二区蜜臀亚洲| 精品亚洲成a人| 久久久久久久久久久电影| 国产精品夜夜嗨| 国产欧美日韩视频在线观看| 懂色av一区二区三区免费看| 国产精品美女久久福利网站| 91在线视频播放| 亚洲精品欧美激情| 欧美性一区二区| 亚洲成a人v欧美综合天堂 | 日韩一区二区三区视频| 美女诱惑一区二区| 精品第一国产综合精品aⅴ| 国产在线精品一区二区夜色| 久久久久久久久久久久久女国产乱 | 亚洲成a人v欧美综合天堂| 欧美日韩电影一区| 人人狠狠综合久久亚洲| 精品国产污网站| 懂色中文一区二区在线播放| 亚洲天堂福利av| 欧美久久高跟鞋激| 精品中文av资源站在线观看| 国产精品水嫩水嫩| 欧美日免费三级在线| 日韩高清国产一区在线| 国产视频在线观看一区二区三区 | 欧美成人vr18sexvr| 国产精品亚洲综合一区在线观看| 亚洲国产高清不卡| 欧洲精品视频在线观看| 麻豆专区一区二区三区四区五区| 欧美激情一区二区三区四区| 日本韩国精品在线| 久久99精品视频| 亚洲日韩欧美一区二区在线|