SE450: Overriding: Method out of scope [17/35] Previous pageContentsNext page

Method out of scope [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
package subclass.ex4;

public class M {
  public static void main(String[] argv) {
    (new B()).m();
  }
}
class A {
  private void p() {System.out.println("A.p");}
  void m() {
    System.out.println("A.m");
    this.p(); // which p?
  }
}
@SuppressWarnings("all")
class B extends A {
  private void p() {System.out.println("B.p");}
}

Another example.

file:M.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
package subclass.exD;

public class M {
  public static void main(String[] argv) {
    (new B()).m();
  }
}
@SuppressWarnings("all")
class B extends subclass.exD.otherPackage.A {
  public void p() {System.out.println("B.p");}
}

file:A.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
package subclass.exD.otherPackage;

public class A {
  void p() {System.out.println("A.p");}
  public void m() {
    System.out.println("A.m");
    this.p(); // which p?
  }
}

Previous pageContentsNext page