- public class Test200 {
- /**
- * @param args
- */
- public static void main(String[] args) {
- A a = new B();
- a.show();
- B b = new C();
- b.show();
- }
- }
- class A {
- public void show() {
- show2();
- }
- public void show2() {
- System.out.println("我");
- }
- }
- class B extends A {
- public void show() {
- super.show();
- }
- public void show2() {
- System.out.println("爱");
- }
- }
- class C extends B {
- public void show() {
- super.show();
- }
- public void show2() {
- System.out.println("你");
- }
- }
复制代码
输出的是 爱 你
- public class Test200 {
- /**
- * @param args
- */
- public static void main(String[] args) {
- A a = new B();
- a.show();
- B b = new C();
- b.show();
- }
- }
- class A {
- public void show() {
- show2();
- }
- public void show2() {
- System.out.println("我");
- }
- }
- class B extends A {
- public void show() {
- super.show2();
- }
- public void show2() {
- System.out.println("爱");
- }
- }
- class C extends B {
- public void show() {
- super.show();
- }
- public void show2() {
- System.out.println("你");
- }
- }
复制代码
输出的是 我 我
两段的代码差别是 类B里show()方法 里super.show()改成了super.show2() |
|