How to call a class of java from another module

Viewed 6765

I have a project with the structure

android/src/com.x.y/A.java

core/src/com.x.y/B.java

I want to call a method from A.java in B. java. I have searched the internet for solutions i have added the lines

implementation project(path: ':core', configuration: 'default')

in android's build.gradle and

implementation project(path: ':android', configuration: 'default')

in core's build.gradle file.

It builds with success but i cannot call the class from B. java

1 Answers

Import the statement

import android.src.com.x.y.A.*;

Then make an object of A.java as follows:

A a = new A();

Then use it's methods in class B wherever you want.

a.pqr()

For further guidance and understanding the concepts, go through official documentation. https://docs.oracle.com/javase/tutorial/

Related