I have an interface containing void doThis();. I’ve implemented the interface in my Main class and it automatically added public void doThis() { ... } to my class. If I’m in Second class, how do I invoke doThis() in Main?
I have an interface containing void doThis(); . I’ve implemented the interface in my
Share
When you implement an interface, you’re making a class. Interfaces are implemented by instance methods on that class.
To invoke an instance method on a class, instantiate the class, and invoke it as you would any other instance method:
Per my example code, you might want to pass an instance of
MainintoSecondinstead of creating the instance insideSecond. You can pass this in via the interface instead of via the concrete class type: