*
The moose likes Beginning Java and the fly likes What is the purpose of instantiating an object in another class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the purpose of instantiating an object in another class?" Watch "What is the purpose of instantiating an object in another class?" New topic
Author

What is the purpose of instantiating an object in another class?

Krystal Tyler
Greenhorn

Joined: Feb 03, 2002
Posts: 4
Hi.
I have seen topics on this here and I was wondering if there actually is a purpose in instantiating an object in another class.
namita pa
Ranch Hand

Joined: Sep 06, 2001
Posts: 56
Originally posted by Krystal Tyler:
Hi.
I have seen topics on this here and I was wondering if there actually is a purpose in instantiating an object in another class.

the objects of one class is instantiated in another if u want to use the methods in the first in the second
thanks
namita
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

Well that is the only way you are actually able to use the object.


Please ignore post, I have no idea what I am talking about.
Shivaji Marathe
Ranch Hand

Joined: Jan 11, 2002
Posts: 203
Instantiating an object is like making it come alive.
Think of it as the difference between a recipe and a cooked dish. The compiled byte code is like the recipe of a dish. You can read it, you know what goes in it, you may know how you are supposed eat it, but you cant' do anything else with it.
When the dish is ready is when you can actually see it, eat it ,smell it etc.
Hope this helps
Krystal Tyler
Greenhorn

Joined: Feb 03, 2002
Posts: 4
So therefore the object instantiated in class B which is of class A has access to all methods from the first class including the private ones? It must have access as well to all the member variables? Thanks.
Shivaji Marathe
Ranch Hand

Joined: Jan 11, 2002
Posts: 203
Krystal :
You can actually write small programs yourself to test this out.
Create a test class with private, protected,public and default access methods. Then create another class and in the main method of that class create an instance of the first class and call all the methods of the first class.
Are you able to compile and run the second class?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the purpose of instantiating an object in another class?
 
Similar Threads
Finding objects of a class dynamically
examination question
object instantiation
Would you consider them Singletons?
Referencing a managed bean object inside another class