Problem with extends

Hi.\I have 3 classes. C1, C2, C3. and C1 extends C3 and C2 extends C3.

And my question is How can I get from C1 to the methods of C2 class??

It is posible?? all methods are public

Classes inherit methods defined in parent classes, therefore both C1 and C2 inherit methods from C3. But C1 doesn’t extend C2, therefore it doesn’t inherit its methods.

An instance of C1 can call public methods of a C2 instance, of course, but that has nothing to do with inheritance.

“An instance of C1 can call public methods of a C2 instance”

what it means?? How it works?? please any pseudocode

Do I think correctly?

suppose:

class C2 have MC2 method.

and now

C1 c1 = new C1();

C2 c2 = new C2();

C1.MC2?? can I do this??

C1 must have a reference to C2 to call. For example:

class C1
{
    C2 c2;

    public void setC2(C2 _c2)
    {
        c2 = _c2;
    }

    public void someOperation()
    {
        c2.publicMethod();
    }
}

thx Martin,

Greetings :slight_smile: