File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can there be Object inside an Object??

 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can there be Object inside an Object??

I mean an Individual is a single object

then heart ,kidneys liver etc are other object within himself....

So in that terms can object be within an Object
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vishal,

it's essentially a key feature of OO languages. You can compose complex objects of simpler ones - not only of primitive values like numbers or strings. So yes, an object can "contain" other objects

In your example heart, kidneys, liver etc. would become members of the surrounding class human or something like this.

Marco
 
Pratik D mehta
Ranch Hand
Posts: 121
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you meant class .
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess so. I just didn't want to make the explaination more complicated than necessary.

@Vishal: As Pratik pointed out you would declare the relationships human, liver, kidneys etc. inside classes and at runtime you would get a graph of related objects.
 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pratik D mehta wrote:I think you meant class .

Pratik class and object are different


class is a DNA for an Object

I just wanted to know whether there can be object within an Object...Any simple realistic examples to get the clear picture


Thnks in Advance ...Love you all
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought my explanation helped to make it clearer

If you declare a class "Human" which has a member of type "Heart" (a class too) you can instantiate those classes and you get an object of type Human which contains an object of type Heart. Better now?
 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marco Ehrentreich wrote:I thought my explanation helped to make it clearer

If you declare a class "Human" which has a member of type "Heart" (a class too) you can instantiate those classes and you get an object of type Human which contains an object of type Heart. Better now?


Yes Marco thanks man.. i think i am too ignorant skipping some words.. sorry for making you retyping stuff again
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem

Hopefully it helped to clarify at least some of your doubts...
 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marco Ehrentreich wrote:No problem

Hopefully it helped to clarify at least some of your doubts...


Yes Marco ,you rock..spending your valuable time making guys like me understand stuff is really like a big support

Proud to be a part of JavaRanch family
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic