• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can there be Object inside an Object??

 
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 121
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you meant class .
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem

Hopefully it helped to clarify at least some of your doubts...
 
Vishal Hegde
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic