How access to a method of base class of a superclass inside a class....

I have :

Class A
Class B : extending A and Z
Class C : extending A and Z
...
Class M : extending A and Z

I need to set/use a Z property/method from A. And I need to check it and other things.
So.... How can I, inside A , have access to Z inherited methods of my superclass (B, C, or any ).
Thanks in advance
Last edited on
An A is not an instance of Z, so it would need some instance of Z to access a non-static method/property of Z.
If you want A to inherent from Z, why don't you just do that?
Because I'm going to use class A for other clases that not need class Z.
I dont want A to inheritate Z, I want to use the Z inheritated methods of B,C, M from inside A.
Thanks
First of all, private members can not be accessed outside of the class they belong to. Protected members can be accessed throughout an inheritance hierarchy. Public Methods can be called anywhere.

Your design doesn't seem to be very good because if A and Z are both base classes on the same level, they should never have to interact with each other. Also you cannot go backwards through the inheritence hierarchy. Base classes cannot call on methods from their derived classes.

If you want to access members in Z, you must do it from B, C, or M in your current design, not A.

If you want to set Z from A, just have A inherit Z and in A's constructors, pass Z the data it needs.

I would like to help but you haven't provided enough information.
Last edited on
I agree, I think either you are confused about your program design (or what OOP can be used for,) or your not elaborating well enough on what you need to do.
Topic archived. No new replies allowed.