This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Krystal Tyler
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well that is the only way you are actually able to use the object.
 
Shivaji Marathe
Ranch Hand
Posts: 203
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 203
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic