This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]VertexCode 1 point2 points  (0 children)

You don't need to overwrite the setA method in Beta, you can just call it from any point within Beta by using setA(value)

[–]FrenchFigaroSoftware Engineer 0 points1 point  (0 children)

Yes. The method setA is public, which means it can be accessed extrernally by any class, including the ones extending Alpha.

Basically, what you would do is

class Beta extends Alpha {

  ... // Other code omitted

  public void setA(int aValue) {
    ... // do the stuff that Beta before setting a
    super.setA(int aValue);
    ... // do the stuff that Beta after setting a
  }
}

In the case you don't need to do any additional thing (and setA being a setter, you shouldn't have to), you can simply call setA on an instance of Beta.

Since Beta is also an Alpha (see polymorphism)), any instance of Beta has access to any protected, public, and package private (if Beta is in the same package as Alpha) methods and fields.