• 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

Does this code will be valid for Composition?

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

this question is related to Composition in Java :




As I think that the Object Integer will be destroyed once this methods execution has been done

So , please let me know if this code will be valid for Composition ??

Inside a Method if I do so

 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, because of the compiler error.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I wrote:No, because of the compiler error.

And you ought to know, no for another reason. Tell us why I think "no for another reason".
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean to say that we must use Integer I as an Instance variable but not as local variable .
so thats why it isn't qualified for Composition ??
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ravi,

there's no composition as far as I can tell... composition is ... a class having a reference to an instance of another class.

So Person below has a date of birth.



Inheritance is an IS-A relationship.

So PersonWithDob below is a Person (note that Person is re-defined) but with a date of birth stored as a String:



Something like that.

Regards,

Justin

 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Kiran V wrote:You mean to say that we must use Integer I as an Instance variable but not as local variable .
so thats why it isn't qualified for Composition ??

If you can then say "My Something HAS-AN Integer", then I would accept that as composition.Here a Car HAS-AN Engine. A Car HAS-SEVERAL Wheels. That is obvious. Your example is less obvious, but if you can say that your Something HAS-A Number, then you have presented an example of composition.
 
Well THAT's new! Comfort me, reliable tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic