public class A {
String username = "Unknown";
public A() {
username = "Virux";
B.method();
}
}
public class B extends A {
public void method() {
System.out.println(super.username);
}
}
Obviously my actual code is much more complex than this.
But how can I get B to see A's 'username' without passing any parameters? Ie; I can't pass 'username' through like "B.method(username);"
I also need this to be an instance, or whatever you want to call it. I need to be able to have multiple A or B objects in an array of Threads.
So if you just try to change 'username' to public static, and my code starts a new thread(that starts a new A or B object) then the 'username' gets changed for all of the other threads. I can't have this.
I was hoping I can do this without an array of 'username' variables and as you can see I'm not too advanced in inheritance yet.
So, all in all: I have a class with an array of threads. "Thread[] threads = new Thread[5];" or whatever. And then I'll have each thread start a new A or B object. In thread: "public void run() { new A(); }" or it can be "new B();" it doesn't matter. Once the A/B object has been started, the 'username' variable will be set in the A object. And then the A object will call a method in B, and B will use the 'username' variable for what I need it for.
Let me know if you need me to clairify anything. Thanks.