permaculture playing cards*
The moose likes Beginning Java and the fly likes Calling Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calling Object" Watch "Calling Object" New topic
Author

Calling Object

Alex Kirk
Ranch Hand

Joined: Aug 13, 2001
Posts: 44
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
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986


(If I am not mistaken.)


Please ignore post, I have no idea what I am talking about.
Alex Kirk
Ranch Hand

Joined: Aug 13, 2001
Posts: 44
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
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
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
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
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
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
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Sounds like a job for inner classes!!!

If your connectionManager class was an inner class of runGnutonic it could access methods and members of the runGnutonic class...

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Alex Kirk
Ranch Hand

Joined: Aug 13, 2001
Posts: 44
Where might I find documentation on such wonderful things?
Alex
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Why don't you sit down and listen to a campfire story?



-Nate
 
GeeCON Prague 2014
 
subject: Calling Object