> > Can you imagine a not contrived example? I.e. why would one inherit from a
> >  class while throwing away the implementation?
> 
> It's precisely to keep the implementation that the parent needs to use
> the getter.
> 
> If the parent does not use the getter, then the sub-class will have to
> re-implement the parts of the parent code that don't use the
> (overloaded) getter.

By "implementation" I meant the instance variable in the base class. If the
getter returns another value, then this base class instance variable has
become useless, obviously.
But I'm not sure that we talk about the same thing...

I mean the following situation:
---
public class A {
  private double a;

  public double getA() {
    return a;
  }
}
---
Then you might want to override the getter while still relying on the base
implementation (i.e. calling the base class getter so that both getters
actually refer to the same variable):
---
public class SubA extends A {
  private Logger log = Logger.getLogger(SubA.class);
  public double getA() {
    log.debug("getA()");
    return super.getA();
  }  
}
---
But I don't understand this:
---
public class AnotherSubA extends A {
  private double subA;

  public double getA() {
    return subA;
  }  
}
---
This looks more like hijacking rather than extending the base class... ;-)

Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to