📄 alteredbinding.java
字号:
package examples.inheritance;
/** A class used to demonstrate how dynamic
* binding can be altered by using the
* <b>super</b> reference.
*/
public class AlteredBinding {
/** Test method for the class
* @param args not used
*/
public static void main( String[] args ) {
D x = new D();
x.g1();
x.g2();
}
}
/** An example super class */
class B {
public void f( String caller ) {
System.out.println( "B.f() called by "
+ caller );
}
}
/** An example subclass */
class D extends B {
public void f( String caller ) {
System.out.println( "D.f() called by "
+ caller );
}
public void g1() {
f( "subclass" ); // this will call D.f()
}
public void g2() {
super.f( "subclass" ); // cannot use B.f() here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -