aspose file tools*
The moose likes Beginning Java and the fly likes Can there be Object inside an Object?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can there be Object inside an Object??" Watch "Can there be Object inside an Object??" New topic
Author

Can there be Object inside an Object??

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1056

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


http://www.lifesbizzare.blogspot.com || OCJP:81%
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

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

Joined: Jul 29, 2010
Posts: 121

I think you meant class .


Understanding is Everything - Peter Lord
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

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

Joined: Aug 01, 2009
Posts: 1056

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

Joined: Mar 07, 2007
Posts: 1282

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

Joined: Aug 01, 2009
Posts: 1056

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

Joined: Mar 07, 2007
Posts: 1282

No problem

Hopefully it helped to clarify at least some of your doubts...
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1056

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can there be Object inside an Object??