This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of TensorFlow 2.0 in Action and have Thushan Ganegedara on-line!
See this thread for details.
Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Calling Object

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

(If I am not mistaken.)
 
Alex Kirk
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Alex Kirk
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where might I find documentation on such wonderful things?
Alex
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you sit down and listen to a campfire story?



-Nate
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic