Follow us on Twitter!
It is never to LATE to become what you never WERE.
Saturday, April 19, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 28
Guests Online: 27
Members Online: 1

Registered Members: 82838
Newest Member: w1zarrd
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

JAVA Containing Classes


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 24-10-06 22:06
Alright, I'm actually pretty sure this is not implemented into java, and not really sure if its even possible, but does anyone know of a way to get the containing object for something your object is in?
i.e.:

public class objA{
public objA()
{
objB b = new objB();
}
}//end of objA class

public class objB{
public objB()
{
}
}//end of objB class

i want some way for b to figure out what objA is. So the memory location or even a returnable object would be great. I have a piece of code for a project and it would be great if I could get some of the data out of that other object.
Again, really pretty sure you can't do this....but still...any ideas?


Author

RE: JAVA Containing Classes


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 24-10-06 22:12
What do you mean "for b to figure out what objA is"? It's kinda hard understanding what you're asking because you seem flustered and more concerned about expressing how you think it's not possible. Pfft
Author

RE: JAVA Containing Classes


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 24-10-06 22:14
haha....sorry. okay...say that object A has a bunch of other vars in it along with objB right? i want to be able to see what those are. I know i cant access back up, things work top down. But i was thinking maybe there was a way to nab the memory location or somehting like that. I need to be able to read those.


Author

RE: JAVA Containing Classes


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 24-10-06 22:22
Why would you want to do that? :xx: When you create an instance of objA you can already reference it's methods and variables (depending on privacy level), there would be no need to call it from within objB inside of objA as far as I can see.
Author

RE: JAVA Containing Classes


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 24-10-06 22:29
yeah...normally there isnt.
but you see i didnt get to create the objA class, only the objB class that is called by objA and i want to access some of its data.


Author

RE: JAVA Containing Classes


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 24-10-06 22:32
I'm not even going to ask what you're doing lol. You can try passing a pointer objA as a parameter in the constructor and than from there call the methods.
Author

RE: JAVA Containing Classes


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 24-10-06 22:38
hah....again cant do that because i cant modify the call to objB. lemme explain what im trying todo.

i have a cs lab and we're writing the "ai" portion for a battleship game. so my "ai" object gets called by the battleship class. i want to access its data so i dont have to guess where this guy has hidden his ship, i can know. I've already written a really nice "ai" so im set on that. Someone in the class just asked me if i knew any way to do that and i started thinking.


Author

RE: JAVA Containing Classes


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 24-10-06 22:50
Yeah, it's hard to grasp EXACTLY what you're intending to do. If you have some more elaborate code that you'd like to post, I might e able to help you from there, otherwise, I'm not quite sure right now.
Author

RE: JAVA Containing Classes


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 26-10-06 07:27
Alright,
I think I understand what you are trying to do. Hopefully this bit of code I just wrote up for you will help..

objA.java
Code
public class objA {

   public static String str;

   public objA() {

      str = new String("Hello World");
      objB b = new objB();

   }

   public static void main(String args[]) {

      objA ob = new objA();

   }

}




objB.java
Code
public class objB {

   public objB() {

      System.out.println(objA.str);

   }

}




Output:
Code
Hello World
Press any key to continue . . .




If this is not what you want just let me know, but I am pretty sure this is what you want. It is pretty self explanitory on what its doing, but if you want me to comment it up just let me know, or I can just explain it in this thread.




Edited by on 26-10-06 07:52