Hi,

Is there a way in Java to implement the following inheritance paradigm: say I have a base class that contains a "data" member of a "base data" type, and a method that does something with that data:

Code:
class BaseData {
...
}

class Base {
   BaseData data;
   void doSomethingWithData() {
       ...
   }
}
Now, I want several classes that will do the SAME thing with data as the base class, but data of the derived class, NOT the base class.

Code:
class DerivedFromBaseData extends BaseData {
   ...
}
Code:
class DerivedFromBase extends Base {
   DerivedFromBaseData data;
   void DoSomethingWithData() {
       ...
    }
}
Obviously, I want to avoid repeated code for doSomethingWithData in each derived class--the method should be the same! Only the "data" it operates on should be different in each class. Unfortunatley, the inherited method will operate on the base class "data", not on the "data" specific to the derived class.

I am sure there is an easy way to do it, I just lack experience in inheritance and ploymorphism to implement it properly. Your help is appreciated. Thanks!