📄 chap19.html
字号:
<P> void instanceMethod() {</P>
<P> }</P>
<P> </P>
<P> final void finalInstanceMethod() {</P>
<P> }</P>
<P> </P>
<P> public void interfaceMethod() {</P>
<P> }</P>
<P>}</P>
</FONT><FONT SIZE="2"><P> </P></P>
<P></FONT><FONT FACE="Courier New">// On CD-ROM in file invoke/ex4/Subclass.java
<P>class Subclass extends ItsABirdItsAPlaneItsSuperclass {</P>
<P> </P>
<P> Subclass() {</P>
<P> this(0); // invokespecial (of an <init</FONT>)</P>
<P> }</P>
<P> </P>
<P> Subclass(int i) {</P>
<P> super(i); // invokespecial (of an <init</FONT>)</P>
<P> }</P>
<P> </P>
<P> private void privateMethod() {</P>
<P> }</P>
<P> </P>
<P> void instanceMethod() {</P>
<P> }</P>
<P> </P>
<P> final void anotherFinalInstanceMethod() {</P>
<P> }</P>
<P> </P>
<P> void exampleInstanceMethod() {</P>
<P> </P>
<P> instanceMethod(); // invokevirtual</P>
<P> super.instanceMethod(); // invokespecial</P>
<P> </P>
<P> privateMethod(); // invokespecial</P>
<P> </P>
<P> finalInstanceMethod(); // invokevirtual</P>
<P> anotherFinalInstanceMethod(); // invokevirtual</P>
<P> </P>
<P> interfaceMethod(); // invokevirtual</P>
<P> </P>
<P> classMethod(); // invokestatic</P>
<P> }</P>
<P>}</P>
</FONT><FONT SIZE="2"><P> </P></P>
<P></FONT><FONT FACE="Courier New">// On CD-ROM in file invoke/ex4/UnrelatedClass.java
<P>class UnrelatedClass {</P>
<P> </P>
<P> public static void main(String args[]) {</P>
<P> </P>
<P> Subclass sc = new Subclass(); // invokespecial (of an <init</FONT>)</P>
<P> Subclass.classMethod(); // invokestatic</P>
<P> sc.classMethod(); // invokestatic</P>
<P> sc.instanceMethod(); // invokevirtual</P>
<P> sc.finalInstanceMethod(); // invokevirtual</P>
<P> sc.interfaceMethod(); // invokevirtual</P>
<P> </P>
<P> InYourFace iyf = sc;</P>
<P> iyf.interfaceMethod(); // invokeinterface</P>
<P> }</P>
<P>}</P>
</FONT><FONT SIZE="2"><P> </P></FONT><FONT FACE="Courier New">end</FONT></P></PRE>
<P>Here are the bytecodes generated by <FONT FACE="Courier New">javac</FONT> for each of these classes (The compiler generates no bytecodes for the <FONT FACE="Courier New">InYourFace</FONT> interface.):</P>
<PRE><P><FONT FACE="Courier New">begin</FONT></P>
<FONT SIZE="2"><P></FONT><FONT FACE="Courier New">// Methods of class ItsABirdItsAPlaneItsSuperclass
<P> </P>
<P>// Method <init</FONT>(int)</P>
<P> 0 aload_0</P>
<P> 1 invokespecial #4 <Method <init</FONT>() of class java.lang.Object</FONT></P>
<P> 4 return</P>
<P> </P>
<P>// Method void classMethod()</P>
<P> 0 return</P>
<P> </P>
<P>// Method void instanceMethod()</P>
<P> 0 return</P>
<P> </P>
<P>// Method void finalInstanceMethod()</P>
<P> 0 return</P>
<P> </P>
<P>// Method void interfaceMethod()</P>
<P> 0 return</P>
<P> </P>
<P>// ------------------------------------</P>
<P>// Methods of class Subclass </P>
<P> </P>
<P>// Method <init</FONT>()</P>
<P> 0 aload_0</P>
<P> 1 iconst_0</P>
<P> 2 invokespecial #4 <Method <init</FONT>(int) of class Subclass</FONT></P>
<P> 5 return</P>
<P> </P>
<P>// Method <init</FONT>(int)</P>
<P> 0 aload_0</P>
<P> 1 iload_1</P>
<P> 2 invokespecial #3 <Method <init</FONT>(int) of class</P>
<P> ItsABirdItsAPlaneItsSuperclass</FONT></P>
<P> 5 return</P>
<P> </P>
<P>// Method void privateMethod()</P>
<P> 0 return</P>
<P> </P>
<P>// Method void instanceMethod()</P>
<P> 0 return</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -