i have a Emp class which have one property empName.i am setting this property in empCreate class.i want to get this property in Main class.
public class Main {
public static void main(String[] args) {
// here i want to get empName which i set it in empCreate.java
}
}
how i can do this. please suggest.
i have Emp.java:
public class Emp {
private String empName;
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
}
and empCreate.java:
public class empCreate {
public static void main(String args[]) {
Emp emp= new Emp();
emp.setEmpName("abc");
}
}
i want to get this property in Main.java which i set it in empCreate.java
You can’t have two main methods. Anyway, I strongly suggest you read the Declaring Member Variables tutorial. This is very basic stuff.
I recommend you refactor your
empCreateclass to include a constructor and a getter for yourEmpinstance. For instance,And then, in your
Mainclass, you can simply do the following –