Here's an example that you may find helpful:
Project_1
has the following class:
ClassProjectOne.java
which consists of:
public class ClassProjectOne {
private int m_Age;
private final int AGE_INPUT = 15;
public ClassProjectOne() {
setAge(AGE_INPUT);
}
public int getAge() {
return m_Age;
}
private void setAge(int age) {
m_Age = age;
}
}
Project_2
has the following class:
ClassProjectTwo.java
which consists of:
public class ClassProjectTwo {
public static void main(String[] args) {
ClassProjectOne t = new ClassProjectOne();
System.out.println(t.getAge());
}
}
In order for this to work, you must right click Project_2
and click on Properties
. Then click on Java Build Path
-> Add...
-> Select Project_1
-> OK
. This sets a Java Build Path.
If your class is static there is no need to initialize a new instance of it.
Hope this helps.