3

I have the following Java class:

public class Dog {

    public void bark() {
        System.out.println("Aw");
    }
}

Is it possible to write a C++ class, say Poodle, which inherits from Dog and overrides the Java bark method?

EDIT1: The big challenge here is that the Poodle C++ class will have to be executed by an embedded JVM created with JNI_CreateJavaVM O.o

EDIT2: Unfortunately this looks impossible :( => But for part 2 of this question you can check here: Is it possible for a C++ program to receive Java method calls from an embedded JVM running through JNI?

  • It is possible to [call Java methods from C++ classes](https://stackoverflow.com/questions/992836/how-to-access-the-java-method-in-a-c-application), so you could define a C++ class that invokes methods from the Java class. – Anderson Green Apr 24 '22 at 02:30
  • Thanks @AndersonGreen. But I don't think that would work. I would like to override a Java method in C++, not call a Java method from C++. – Roger Kasinsky Apr 24 '22 at 02:42
  • 1
    I wouldn't expect it. The Java object model supports class introspection (e.g. a class hierarchy can be interrogated at run time) which the C++ object model does not (e.g. all relationships are specified at compile time). Having a C++ class derived from something that is not known until runtime (including deriving a C++ class from a Java class) conflicts with the C++ object model. I suppose it might be notionally possible with a C++ compiler that targets a specific JVM platform - but such a solution would be specific to that compiler and that JVM. – Peter Apr 24 '22 at 02:44
  • Great answer, @Peter. This should be impossible :( Do you mind checking this now => https://stackoverflow.com/questions/71985100/is-it-possible-for-a-c-program-to-receive-java-method-calls-from-an-embedded-j – Roger Kasinsky Apr 24 '22 at 02:48

0 Answers0