How do you call subclass method in superclass, in Java?

PrimeCubed :

I am planning on coding an API. I want to call a method from the API super class, that will be declared in the class that extends the API class. Is there a way to do this? Thanks - PrimeCubed

F_Schmidt :

There is no way. Reason is that a subclass is a different object type. You could try to think about a way to parse your superobject into a subobject.

Edit: I have no idea of what your API is doing or what so ever. If you can, then just post a little more detail. Usually an extension USES the API. So if you think in plugins, then you offer the basic structure and use interfaces to create general objects.

Maybe events are a solution for you?

If you want more concrete hints, then please post more details.

Edit 2: Check out abstract classes and interfaces if you are trying to create an API. That is a very good way to go. And even further, the observer pattern could be useful for registering some listeners etc.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=396413&siteId=1
Recommended