This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
What is the purpose of instantiating an object in another class?
Krystal Tyler
Greenhorn
Joined: Feb 03, 2002
Posts: 4
posted
0
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
posted
0
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
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
posted
0
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
posted
0
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
posted
0
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?