Use subclass methods from another subclass, side casting?

In Java, I got the job. I could describe my problem with her as a whole as follows:

Create three classes AB and C.

Class A has instance variables j, k, l, setter and getter methods, as well as the x method, which computes based on them.

Class B is a subclass of A and overrides method x with the same empty signature using j, k, l.

Class C is also a subclass of A and has an extra class y, which makes other junk.

Now create an instance of an object of class C, set its variables, execute method x, and then use the overridden version of method x from class B.

My question is: how do I do this last part? I think either the question is incorrect or I am interpreting it incorrectly. Can I pass an object of class C to an object of class B and then use the version of class x ()? I don’t know much about what objects are and what determines whether it is possible to drop from one thing to another. Acceleration can be as loss-making as horizontal / side casting, but I never heard of the latter. Is it impossible to use a class B method from class C without creating an instance of class C and rebuilding an object of class B from its own variables? I mean?

Application:

. ? C B " [] ". , ? , ? x A, B, B C /, , . j, k l B C. , . ?

:

, , , . B C A, B C? , ?

:

, , Java . , JavaScript PHP "" , . , B:x() C , , x C. .

+4
1

, , , . -, , ( , ClassCastException) .

, , - Object # equals. equals java.lang.Object . , , , , , , , . .

, , , (, ), . , , .

C B, B C B C , :

class C extends A {
    private B b; // instance member

    public C(B b) {
        this.b = b;
    }

    public void x() {
        // do stuff
        b.x();
    }
} 
+3

All Articles