📄 chap08.html
字号:
<P> for (int i = 0; i < wagCount; ++i) {</P>
<P> System.out.print(", wag");</P>
<P> }</P>
<P> System.out.println(".");</P>
<P> }</P>
<P> </P>
<P> public String toString() {</P>
<P> </P>
<P> return "Woof!";</P>
<P> }</P>
<P>}</P>
</FONT><FONT SIZE="2"><P> </P></P>
<P></FONT><FONT FACE="Courier New">// On CD-ROM in file linking/ex4/CockerSpaniel.java
<P>class CockerSpaniel extends Dog implements Friendly {</P>
<P> </P>
<P> // How many times this Cocker Spaniel woofs when saying hello.</P>
<P> private int woofCount = ((int) (Math.random() * 4.0)) + 1;</P>
<P> </P>
<P> // How many times this Cocker Spaniel wimpers when saying</P>
<P> // goodbye.</P>
<P> private int wimperCount = ((int) (Math.random() * 3.0)) + 1;</P>
<P> </P>
<P> public void sayHello() {</P>
<P> </P>
<P> // Wag that tail a few times.</P>
<P> super.sayHello();</P>
<P> </P>
<P> System.out.print("Woof");</P>
<P> for (int i = 0; i < woofCount; ++i) {</P>
<P> System.out.print(", woof");</P>
<P> }</P>
<P> System.out.println("!");</P>
<P> }</P>
<P> </P>
<P> public void sayGoodbye() {</P>
<P> </P>
<P> System.out.print("Wimper");</P>
<P> for (int i = 0; i < wimperCount; ++i) {</P>
<P> System.out.print(", wimper");</P>
<P> }</P>
<P> System.out.println(".");</P>
<P> }</P>
<P>}</P>
</FONT><FONT SIZE="2"><P> </P></P>
<P></FONT><FONT FACE="Courier New">// On CD-ROM in file linking/ex4/Cat.java
<P>class Cat implements Friendly {</P>
<P> </P>
<P> </P>
<P> public void eat() {</P>
<P> </P>
<P> System.out.println("Chomp, chomp, chomp.");</P>
<P> }</P>
<P> </P>
<P> public void sayHello() {</P>
<P> </P>
<P> System.out.println("Rub, rub, rub.");</P>
<P> }</P>
<P> </P>
<P> public void sayGoodbye() {</P>
<P> </P>
<P> System.out.println("Scamper.");</P>
<P> }</P>
<P> </P>
<P> protected void finalize() {</P>
<P> </P>
<P> System.out.println("Meow!");</P>
<P> }</P>
<P>}</P>
</FONT><FONT SIZE="2"><P> </P></FONT><FONT FACE="Courier New">end</FONT></P></PRE>
<P>Assume these types are loaded into a Java Virtual Machine that organizes objects by placing the instance variables declared in superclasses into the object image before those declared in subclasses, and by placing the instance variables for each individual class in their order of appearance in the class file. Assuming there are no instance variables in class <FONT FACE="Cou
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -