Is there a way to automatically specify the object which called another object, as in JavaScript windowing's "parent"? For example, if I have myClass.java, which creates mySubClass.java and implements the function bigFunc(), could I from mySubClass.java call parent.bigFunc()? Thanks, Alex Kirk
Please ignore post, I have no idea what I am talking about.
Alex Kirk
Ranch Hand
Joined: Aug 13, 2001
Posts: 44
posted
0
Ummm, nope. That actually calls the superclass of a class; i.e., for java.lang.String, it calls java.lang.Object. I'm talking about instantiated objects, just to be clear. Alex
Bindesh Vijayan
Ranch Hand
Joined: Aug 21, 2001
Posts: 104
posted
0
IMO Chris is right.If it does'nt work.Then you want something else.Please put your question in some other way. THANKS.
Alex Kirk
Ranch Hand
Joined: Aug 13, 2001
Posts: 44
posted
0
Let me clarify with some code. { public int x = 0; public static void main(String args[]) { System.out.println("running..."); test2 t = new test2(); t.check(); } }
{ public void check() { System.out.println(super.x); } } When I attempt to run test.java, I get: ./test2.java:5: No variable x defined in class java.lang.Object. System.out.println(super.x); ^ Does that make more sense? Sorry for the confusion. Alex
Bindesh Vijayan
Ranch Hand
Joined: Aug 21, 2001
Posts: 104
posted
0
Thanks for clarifying(so promptly... ) The reason why you are getting such an error is, by default every class gets inherited from Object class when you don't explicitly inherit from other.This is what is happening in your case since your Test.java gets implicitly inherited from Object. To make it fine try extending Test with Test2. THANKS.
Alex Kirk
Ranch Hand
Joined: Aug 13, 2001
Posts: 44
posted
0
That's fine and dandy in this little test scenario, but it won't really help me in my real application. For example, this application has a class connectionManager, which extends Thread. I need it to do so to handle traffic on a UDP Socket in the background. I instantiate it and .start() it from class runGnutonic, which has objects like a configurationManager that I'd like to access. How could I either a) call a method of or b) grab public data from runGnuonic, while within connectionManager? Alex
Bindesh Vijayan
Ranch Hand
Joined: Aug 21, 2001
Posts: 104
posted
0
Well I have no knowledge inNetworking. But one thing is for sure that you can always define such member as class member i.e.Static. Thanks