I have three classes.
Parent.class
child1.class
child2.class
These classes are not parent and children based on your definitions below.
public class child1
{
public void send()
{
x = a+b;
}
}
public class child2
{
public void getValue()
{
QUESTION: I want to access the value of x?
How can i access without calling send()?
}
}
QUESTION: I want to access the value of x in child2.class,getValue() method without calling send() of child1.class?
x is a local variable to the send() method. After the method runs, it is "out of scope" and essentially disappears. You could declare x as a public variable in the class, then you could just reference it via by saying c1.x. *BUT* child2 would have to have a reference to the child1 variable.
And also if i import child1.class in child2.class. DID I have make reference to child1.class in child2.class?
As the program stands now, you don't need to import either one. If you were to reference child1 inside of child2, then you would have to import child1. If you don't reference child2 inside of child1, then you don't have to import it. (Someone correct me if I'm wrong, because I'm not positive on this.)