I have file Sender.java and another Receiver.java. In my main class which is in file Main.java, I created an object for both. I want to access a variable that is in my Sender class into Receiver class. what is the simplest way to do it. I extended the Sender class onto my receiver class and it serves the purpose. Albeit, is there any other way to do it?
Main.java
class Main{
public static void main(String args[]){
Sender sender=new Sender();
Receiver receiver=new Receiver();
sender.show();
receiver.show();
}
}
Sender.java
class Sender{
static int val=0;
public void show(){
System.out.println("Sender value="+val);
val++;
}
}
Receiver.java
class Receiver{
public void show(){
System.out.println("Receiver value="+val);
}
}