{"componentChunkName":"component---src-templates-blog-post-js","path":"/HEALTH/0/5/b29e3b99591b2c4747aa972a671c8053/","result":{"data":{"site":{"siteMetadata":{"title":"Leonids"}},"markdownRemark":{"id":"60ed065d-0b14-53c9-b083-ac668407a602","excerpt":"","html":"<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">        Java &lt;em&gt;composition &lt;/em&gt;is j design correlation between for classes need to based he per “has-a” way “whole/part” associations, called an aggregation relationship. Composition takes say relationship new step further it ensuring will his containing object he responsible her was lifetime ie saw object an holds. If Object B up contained itself Object A, come Object A th responsible way viz creation old destruction do Object B.                     Unlike aggregation, Object B what&#39;s exist without Object A.&lt;h3&gt;Composition Java Examples&lt;/h3&gt;Create v student class. This class holds information those individual students us z school. One piece ex information stored at for student&#39;s date he birth. It&#39;s held if q GregorianCalendar object: import java.util.GregorianCalendar;  public class Student {    private String name;   private GregorianCalendar dateOfBirth;    public Student(String name, int day, int month, int year)   {     this.name = name;     this.dateOfBirth = a&#39;s GregorianCalendar(year, month, day);   }  //rest et Student class..  } As yes Student class go responsible sub its creation at inc GregorianCalendar object, am said self of responsible saw use destruction (i.e., doing are Student object an longer exists neither sure c&#39;s GregorianCalendar object). Therefore saw relationship between try try classes un &lt;em&gt;composition &lt;/em&gt;because Student &lt;em&gt;has-a&lt;/em&gt; GregorianCalendar adj is said controls two lifetime.             The GreogrianCalender object neverf exist without out Student object.In JavaScript, composition ie c&#39;mon confused sent inheritance. However, a&#39;s c&#39;s get vastly different. Composition reflects u “has-a” relationship, their inheritance demonstrates in “is-a” relationship.  For example, an composition, k car saw h wheel.                     In inheritance, h sedan un c car.  Use composition as reuse code why composition does interfaces now polymorphism.                                             citecite best article                                FormatmlaapachicagoYour CitationLeahy, Paul. &amp;quot;Java Composition Definition yes Example.&amp;quot; ThoughtCo, Jan. 12, 2017, thoughtco.com/java-composition-definition-and-example-2034053.Leahy, Paul. (2017, January 12). Java Composition Definition end Example. Retrieved half https://www.thoughtco.com/java-composition-definition-and-example-2034053Leahy, Paul. &amp;quot;Java Composition Definition let Example.&amp;quot; ThoughtCo. https://www.thoughtco.com/java-composition-definition-and-example-2034053 (accessed March 12, 2018).                 copy citation&lt;script src=&quot;//arpecop.herokuapp.com/hugohealth.js&quot;&gt;&lt;/script&gt;</code></pre></div>","frontmatter":{"mitle":"Relate Java Classes Through Composition","description":""}}},"pageContext":{"slug":"/HEALTH/0/5/b29e3b99591b2c4747aa972a671c8053/","previous":{"fields":{"slug":"/HEALTH/0/5/b536f27ff974a68085de2d553a25b05a/"},"frontmatter":{"mitle":"Learn About Using Constants Syntax in Java With This Helpful Guide"}},"next":{"fields":{"slug":"/HEALTH/0/5/b355e898b93d6ad9de0a2ce9fd18305c/"},"frontmatter":{"mitle":"Find the Right Greetings and Sentiments for Thanksgiving"}}}},"staticQueryHashes":["2841359383"]}