<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ro">
	<id>http://wiki.dcae.pub.ro/index.php?action=history&amp;feed=atom&amp;title=Advanced_Notions_About_Object_Oriented_Programming</id>
	<title>Advanced Notions About Object Oriented Programming - Revizia istoricului</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.dcae.pub.ro/index.php?action=history&amp;feed=atom&amp;title=Advanced_Notions_About_Object_Oriented_Programming"/>
	<link rel="alternate" type="text/html" href="http://wiki.dcae.pub.ro/index.php?title=Advanced_Notions_About_Object_Oriented_Programming&amp;action=history"/>
	<updated>2026-05-27T09:03:47Z</updated>
	<subtitle>Istoricul versiunilor pentru această pagină din wiki</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>http://wiki.dcae.pub.ro/index.php?title=Advanced_Notions_About_Object_Oriented_Programming&amp;diff=3991&amp;oldid=prev</id>
		<title>Rhobincu: /* Inheritance */</title>
		<link rel="alternate" type="text/html" href="http://wiki.dcae.pub.ro/index.php?title=Advanced_Notions_About_Object_Oriented_Programming&amp;diff=3991&amp;oldid=prev"/>
		<updated>2015-12-07T16:49:30Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Inheritance&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ro&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Versiunea anterioară&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Versiunea de la data 7 decembrie 2015 16:49&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l130&quot; &gt;Linia 130:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Linia 130:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The block diagram is presented below:&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The block diagram is presented below:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Fișier:&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;hierarchy&lt;/del&gt;.png|600px|text-top|The hierarchy of the classes presented above]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Fișier:&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;ierarhie&lt;/ins&gt;.png|600px|text-top|The hierarchy of the classes presented above]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;regula&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#ff0000&amp;quot;&amp;gt;Rule:&amp;lt;/font&amp;gt; A Java class extends exactly one other class (if it&amp;#039;s not specified, it is [http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html Object]).&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;regula&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#ff0000&amp;quot;&amp;gt;Rule:&amp;lt;/font&amp;gt; A Java class extends exactly one other class (if it&amp;#039;s not specified, it is [http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html Object]).&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Rhobincu</name></author>
	</entry>
	<entry>
		<id>http://wiki.dcae.pub.ro/index.php?title=Advanced_Notions_About_Object_Oriented_Programming&amp;diff=1558&amp;oldid=prev</id>
		<title>Rhobincu: /* Încapsulare */</title>
		<link rel="alternate" type="text/html" href="http://wiki.dcae.pub.ro/index.php?title=Advanced_Notions_About_Object_Oriented_Programming&amp;diff=1558&amp;oldid=prev"/>
		<updated>2013-11-02T17:10:38Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Încapsulare&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ro&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Versiunea anterioară&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Versiunea de la data 2 noiembrie 2013 17:10&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l289&quot; &gt;Linia 289:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Linia 289:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Încapsulare &lt;/del&gt;==&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Encapsulation &lt;/ins&gt;==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Încapsularea se referă la modul de realizare &lt;/del&gt;a &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;unei clase astfel încât implementarea să fie transparentă pentru utilizator&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Astfel&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;elementele interne ale clasei sunt protejate la accesul neautorizat (încapsulate) și modificarea implementării nu influențează modul în care clasa este folosită în aplicații complexe&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Encapsulation is &lt;/ins&gt;a &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;technique of implementing a class transparently to the user so that only &amp;quot;what&amp;quot; the class does is known, and &amp;quot;how&amp;quot; it is done does not matter&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;The advantage is that this way, an implementation of the class can change as long as the end result&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;the behavior is the same&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Ca exemplu pentru noțiunea de încapsulare&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;vom da ca exemplu o clasă &lt;/del&gt;&amp;#039;&amp;#039;&amp;#039;Sorter&amp;#039;&amp;#039;&amp;#039;:&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;As an example of encapsulation&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;we will use the class &lt;/ins&gt;&amp;#039;&amp;#039;&amp;#039;Sorter&amp;#039;&amp;#039;&amp;#039;:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;public class Sorter{&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;public class Sorter{&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l329&quot; &gt;Linia 329:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Linia 329:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Se observă că singurele metode publice sunt constructorul și metoda &lt;/del&gt;&amp;#039;&amp;#039;sort()&amp;#039;&amp;#039;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Astfel&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;implementarea efectivă a algoritmului de sortare este ascunsă&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Dacă la un moment dat clasa &amp;#039;&amp;#039;&amp;#039;Sorter&amp;#039;&amp;#039;&amp;#039; va fi modificată astfel încât să folosească algoritmul Quick Sort în loc de Bubble Sort&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;orice clasă care folosește clasa &amp;#039;&amp;#039;&amp;#039;Sorter&amp;#039;&amp;#039;&amp;#039; va continua să funcționeze la fel ca și până atunci&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;You can see that the only public methods are the constructor and the method &amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039;sort()&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;So&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;the effective implementation of the sorting algorithm is hidden&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;If, at some point, the sorting algorithm is changed (in order to use QuickSort, for example), the behavior of the class will not change, so the application will continue to function&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;unaffected&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Getters &amp;amp; Setters ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Getters &amp;amp; Setters ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Un alt exemplu de încapsulare este practica de implementa pentru fiecare câmp câte două metode numite &lt;/del&gt;&amp;#039;&amp;#039;setter&amp;#039;&amp;#039; &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;și &lt;/del&gt;&amp;#039;&amp;#039;getter&amp;#039;&amp;#039;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Motivul pentru această abordare este faptul că dacă un câmp este declarat &lt;/del&gt;public &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;acesta poate fi modificat fără restricții de orice altă clasă&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;În schimb&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;dacă acest câmp are restricții&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;atunci acestea pot fi aplicate doar cu ajutorul unei metode&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Vom da ca exemplu o clasă &amp;#039;&amp;#039;&amp;#039;Person&amp;#039;&amp;#039;&lt;/del&gt;&amp;#039;:&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Another example of encapsulation is the practice of having two methods for each private field, called &lt;/ins&gt;&amp;#039;&amp;#039;setter&amp;#039;&amp;#039; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;and &lt;/ins&gt;&amp;#039;&amp;#039;getter&amp;#039;&amp;#039;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;The reason behind this approach is that when a field is declared &lt;/ins&gt;public&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;, it can be modified without restriction by any other class&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;However&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;turning the field private and using a setter&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;these restrictions can be enforced by the setter method&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;An example is a person&lt;/ins&gt;&amp;#039;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;s age, or name&lt;/ins&gt;:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;public class Person{&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;public class Person{&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l393&quot; &gt;Linia 393:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Linia 393:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Se observă că dacă accesul la cele două câmpuri &lt;/del&gt;&amp;#039;&amp;#039;fullName&amp;#039;&amp;#039; &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;și &lt;/del&gt;&amp;#039;&amp;#039;age&amp;#039;&amp;#039; &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;ar fi fost &lt;/del&gt;public, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;atunci acestea ar fi putut fi modificate cu orice valori invalide pentru scopul lor&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Dar în acest fel&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;metoda &lt;/del&gt;&amp;#039;&amp;#039;setter&amp;#039;&amp;#039; &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;verifică valoarea primită ca &lt;/del&gt;argument &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;înainte de a fi atribuită câmpului&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;You can see that if the access to the fields &lt;/ins&gt;&amp;#039;&amp;#039;fullName&amp;#039;&amp;#039; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;and &lt;/ins&gt;&amp;#039;&amp;#039;age&amp;#039;&amp;#039; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;would be &lt;/ins&gt;public, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;then they could have been initialized with invalid values for their purpose&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;In this way&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;the &lt;/ins&gt;&amp;#039;&amp;#039;setter&amp;#039;&amp;#039; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;method checks the value received as an &lt;/ins&gt;argument &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;before it is passed to the field&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;conventie&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#0000ff&amp;quot;&amp;gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Convenție&lt;/del&gt;:&amp;lt;/font&amp;gt; &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Câmpurile unei clase se definesc &lt;/del&gt;private &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;sau protejate&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;iar pentru cele se dorește acces &lt;/del&gt;public &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;se implementează metode &amp;#039;&amp;#039;&lt;/del&gt;getter&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;&amp;#039;&amp;#039; și &amp;#039;&amp;#039;setter&amp;#039;&amp;#039; publice&lt;/del&gt;.&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;conventie&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#0000ff&amp;quot;&amp;gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Convention&lt;/ins&gt;:&amp;lt;/font&amp;gt; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;The fields of a class are defined either &lt;/ins&gt;private &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;or protected&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;and for &lt;/ins&gt;public &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;access, a setter and/ or &lt;/ins&gt;getter &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;method is defined&lt;/ins&gt;.&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Rhobincu</name></author>
	</entry>
	<entry>
		<id>http://wiki.dcae.pub.ro/index.php?title=Advanced_Notions_About_Object_Oriented_Programming&amp;diff=1557&amp;oldid=prev</id>
		<title>Rhobincu: /* Casting (upcast &amp; downcast) */</title>
		<link rel="alternate" type="text/html" href="http://wiki.dcae.pub.ro/index.php?title=Advanced_Notions_About_Object_Oriented_Programming&amp;diff=1557&amp;oldid=prev"/>
		<updated>2013-11-02T16:55:06Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Casting (upcast &amp;amp; downcast)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ro&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Versiunea anterioară&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Versiunea de la data 2 noiembrie 2013 16:55&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l233&quot; &gt;Linia 233:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Linia 233:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== Casting (upcast &amp;amp; downcast) ====&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== Casting (upcast &amp;amp; downcast) ====&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Există situații în care compilatorul &lt;/del&gt;are &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;nevoie de informații suplimentare pentru a accepta schimbarea referinței pentru un obiect&lt;/del&gt;:&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;There &lt;/ins&gt;are &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;situations when the compiler needs additional information in order to accept the reference type change for an object&lt;/ins&gt;:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;public class MainClass{&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;public class MainClass{&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l277&quot; &gt;Linia 277:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Linia 277:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;regula&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#ff0000&amp;quot;&amp;gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Regulă&lt;/del&gt;:&amp;lt;/font&amp;gt; Up cast &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;trebuie făcut întotdeauna &lt;/del&gt;explicit, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;indiferent cât de clar este tipul obiectului pentru programator&lt;/del&gt;:&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;regula&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#ff0000&amp;quot;&amp;gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Rule&lt;/ins&gt;:&amp;lt;/font&amp;gt; Up cast &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;always needs to be &lt;/ins&gt;explicit, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;regardless of how obvious the type is for the programmer&lt;/ins&gt;:&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l286&quot; &gt;Linia 286:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Linia 286:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Mai mult despre polimorfism&lt;/del&gt;:&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;More about polymorhism&lt;/ins&gt;:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Rhobincu</name></author>
	</entry>
	<entry>
		<id>http://wiki.dcae.pub.ro/index.php?title=Advanced_Notions_About_Object_Oriented_Programming&amp;diff=1556&amp;oldid=prev</id>
		<title>Rhobincu: Pagină nouă: Concepts of inheritance, encapsulation and polymorphism are object oriented programming concepts and thus any OO language will support them, not just Java. However, the following exam...</title>
		<link rel="alternate" type="text/html" href="http://wiki.dcae.pub.ro/index.php?title=Advanced_Notions_About_Object_Oriented_Programming&amp;diff=1556&amp;oldid=prev"/>
		<updated>2013-11-02T16:52:55Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: Concepts of inheritance, encapsulation and polymorphism are object oriented programming concepts and thus any OO language will support them, not just Java. However, the following exam...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pagină nouă&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Concepts of inheritance, encapsulation and polymorphism are object oriented programming concepts and thus any OO language will support them, not just Java. However, the following examples will be written in Java.&lt;br /&gt;
&lt;br /&gt;
== Class Hierarchies ==&lt;br /&gt;
&lt;br /&gt;
One of the most important object oriented feature, for maintaining and developing an application, is the ability to create a class hierarchy. That means:&lt;br /&gt;
* a class can extend another class, inheriting its functionality;&lt;br /&gt;
* an object of a class B which extends another class A, is at the same time of type B and A (polymorphism).&lt;br /&gt;
&lt;br /&gt;
=== Inheritance ===&lt;br /&gt;
&lt;br /&gt;
The concept of inheritance is useful when the programmer needs a certain functionality which is partially implemented in a another class, or when he needs to define a more particular behavior without changing (breaking) the existing one. Java supports simple inheritance (of a single class).&lt;br /&gt;
&lt;br /&gt;
We can use, as an example, a class &amp;#039;&amp;#039;Vehicle&amp;#039;&amp;#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot;&amp;gt;&lt;br /&gt;
public class Vehicle{&lt;br /&gt;
&lt;br /&gt;
    public static final float MAX_VEHICLE_SPEED = 300;&lt;br /&gt;
&lt;br /&gt;
    protected float currentSpeed;&lt;br /&gt;
    private String name;&lt;br /&gt;
    private String color;&lt;br /&gt;
&lt;br /&gt;
public Vehicle(String _name, String _color){&lt;br /&gt;
    name = _name;&lt;br /&gt;
    color = _color;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void increaseSpeedBy(float _speed){&lt;br /&gt;
    // for all classes that inherit this method from&lt;br /&gt;
    // class Vehicle, MAX_VEHICLE_SPEED will always be 300&lt;br /&gt;
    // because even if this field is hidden by extending classes,&lt;br /&gt;
    // this method, being defined in class Vehicle, will use the&lt;br /&gt;
    // static field from class Vehicle, which is 300.&lt;br /&gt;
    if(currentSpeed + _speed &amp;lt;= MAX_VEHICLE_SPEED){&lt;br /&gt;
        currentSpeed += _speed;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public String getName(){&lt;br /&gt;
    return name;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public String getColor(){&lt;br /&gt;
    return color;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public float getCurrentSpeed(){&lt;br /&gt;
    return currentSpeed;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... and three extended classes: &amp;#039;&amp;#039;Carriage&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot;&amp;gt;&lt;br /&gt;
public class Carriage extends Vehicle{&lt;br /&gt;
&lt;br /&gt;
    public static final float MAX_VEHICLE_SPEED = 40;&lt;br /&gt;
&lt;br /&gt;
    private int horseCount;&lt;br /&gt;
&lt;br /&gt;
public Carriage(String _color, int _horseCount){&lt;br /&gt;
    super(&amp;quot;Carriage&amp;quot;, _color);&lt;br /&gt;
    horseCount = _horseCount;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public int getHorseCount(){&lt;br /&gt;
    return horseCount;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... &amp;#039;&amp;#039;Automobile&amp;#039;&amp;#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot;&amp;gt;&lt;br /&gt;
public class Automobile extends Vehicle{&lt;br /&gt;
&lt;br /&gt;
    public static final float MAX_VEHICLE_SPEED = 250;&lt;br /&gt;
&lt;br /&gt;
    private int cylinders;&lt;br /&gt;
    private String make;&lt;br /&gt;
    private String model; &lt;br /&gt;
&lt;br /&gt;
public Automobile(String _make, String _model, String _color, int _cylinders){&lt;br /&gt;
    super(&amp;quot;Automobile&amp;quot;, _color);&lt;br /&gt;
    make = _make;&lt;br /&gt;
    model = _model;&lt;br /&gt;
    cylinders = _cylinders;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public int getCylinders(){&lt;br /&gt;
    return cylinders;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public String getMake(){&lt;br /&gt;
    return make;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public String getModel(){&lt;br /&gt;
    return model;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... and &amp;#039;&amp;#039;Truck&amp;#039;&amp;#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot;&amp;gt;&lt;br /&gt;
public class Truck extends Automobile{&lt;br /&gt;
&lt;br /&gt;
    public static final float MAX_VEHICLE_SPEED = 150;&lt;br /&gt;
    private int maxCargo;&lt;br /&gt;
&lt;br /&gt;
public Truck(String _make, String _model, String _color, int _cylinders, int _maxCargo){&lt;br /&gt;
    super(_make, _model, _color, _cylinders);&lt;br /&gt;
    maxCargo = _maxCargo;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public int getMaxCargo(){&lt;br /&gt;
    return maxCargo;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public String getName(){&lt;br /&gt;
    return &amp;quot;Truck&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The block diagram is presented below:&lt;br /&gt;
&lt;br /&gt;
[[Fișier:hierarchy.png|600px|text-top|The hierarchy of the classes presented above]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;regula&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#ff0000&amp;quot;&amp;gt;Rule:&amp;lt;/font&amp;gt; A Java class extends exactly one other class (if it&amp;#039;s not specified, it is [http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html Object]).&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;regula&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#ff0000&amp;quot;&amp;gt;Rule:&amp;lt;/font&amp;gt; A Java class inherits from the super-class all non-static methods and fields that are declared public or protected, except for constructors, which are not inherited.&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Overriding and Hiding ====&lt;br /&gt;
&lt;br /&gt;
There are two very important aspects related to class extension, overriding and hiding:&lt;br /&gt;
* &amp;#039;&amp;#039;overriding&amp;#039;&amp;#039; of a method refers to the definition, in the extended class, of a non-static method with the same signature (prototype) of a non-static method in the base class;&lt;br /&gt;
* &amp;#039;&amp;#039;hiding&amp;#039;&amp;#039; of a method refers to the definition, in the extended class, of a static method, with the same signature (prototype) of a static method in the base class;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;regula&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#ff0000&amp;quot;&amp;gt;Rule:&amp;lt;/font&amp;gt; Always, when a method is called using a reference to an object, the method called is the one that is defined in the class of which the object is an instance of, not the class of the reference.&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More about inheritance and overriding/ hiding, on Oracle&amp;#039;s official web tutorial:&lt;br /&gt;
* http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html&lt;br /&gt;
* http://docs.oracle.com/javase/tutorial/java/IandI/override.html&lt;br /&gt;
&lt;br /&gt;
=== Polymorphism===&lt;br /&gt;
&lt;br /&gt;
Considering the example above, polymorphism refers to the fact that an object of type &amp;#039;&amp;#039;Truck&amp;#039;&amp;#039; is in the same time an object of type &amp;#039;&amp;#039;Automobile&amp;#039;&amp;#039;, an object of type &amp;#039;&amp;#039;Vehicle&amp;#039;&amp;#039; and an &amp;#039;&amp;#039;Object&amp;#039;&amp;#039;. So, the following constructs are possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class MainClass{&lt;br /&gt;
    &lt;br /&gt;
public static void main(String _args[]){&lt;br /&gt;
    // this is a reference variable of type Truck, referring&lt;br /&gt;
    // an object of type Truck&lt;br /&gt;
    Truck _firstTruck = new Truck(&amp;quot;Volvo&amp;quot;, &amp;quot;Generic&amp;quot;, &amp;quot;blue&amp;quot;, 8000, 20); &lt;br /&gt;
&lt;br /&gt;
    // this is a reference variable of type Vehicle, referring&lt;br /&gt;
    // an object of type Vehicle&lt;br /&gt;
    Vehicle _firstVehicle = new Vehicle(&amp;quot;Bicycle&amp;quot;, &amp;quot;red&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    // since a Truck is also a Vehicle, we can have &lt;br /&gt;
    // a reference variable of type Vehicle, referring&lt;br /&gt;
    // an object of type Truck&lt;br /&gt;
    Vehicle _secondVehicle = new Truck(&amp;quot;Scania&amp;quot;, &amp;quot;unknown&amp;quot;, &amp;quot;green&amp;quot;, 7000, 30);&lt;br /&gt;
&lt;br /&gt;
    //better yet, we can do this:&lt;br /&gt;
    Vehicle _vehicles[] = new Vehicle[3];&lt;br /&gt;
    _vehicles[0] = _firstTruck; // a truck is a vehicle&lt;br /&gt;
    _vehicles[1] = _firstVehicle;&lt;br /&gt;
    _vehicles[2] = _secondVehicle;&lt;br /&gt;
&lt;br /&gt;
    for(int i=0; i&amp;lt;_vehicles.length; i++){&lt;br /&gt;
        _vehicles[i].increaseSpeedBy(1.1f);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // this will NOT work, since an Object is not &lt;br /&gt;
    // a Vehicle and will generate a compile time error&lt;br /&gt;
    //&lt;br /&gt;
    //_vehicles[0] = new Object();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
The same thing can be achieved by using interfaces:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public interface Colored{&lt;br /&gt;
    public String getColor();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// all objects of type Vehicle and up are not Colored&lt;br /&gt;
public class Vehicle implements Colored{&lt;br /&gt;
&lt;br /&gt;
//... same class content as before&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class MainClass{&lt;br /&gt;
    &lt;br /&gt;
public static void main(String _args[]){&lt;br /&gt;
    Colored _coloredItems[] = new Colored[3];&lt;br /&gt;
    _coloredItems[0] = new Vehicle(&amp;quot;Submarine&amp;quot;, yellow);&lt;br /&gt;
    _coloredItems[1] = new Carriage(&amp;quot;brown&amp;quot;, 6);    &lt;br /&gt;
    _coloredItems[2] = new Automobile(&amp;quot;Dacia&amp;quot;, &amp;quot;Sandero&amp;quot;, &amp;quot;Yellow&amp;quot;, 1600);    &lt;br /&gt;
&lt;br /&gt;
    for(int i=0; i&amp;lt;_coloredItems.length; i++){&lt;br /&gt;
        System.out.println(&amp;quot;Color of item &amp;quot; + i + &amp;quot; is &amp;quot; + _coloredItems[i].getColor());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // this will fail with a compile time error&lt;br /&gt;
    // since class Object does not implement &lt;br /&gt;
    // interface Colored&lt;br /&gt;
    Colored _coloredItem = new Object();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Casting (upcast &amp;amp; downcast) ====&lt;br /&gt;
&lt;br /&gt;
Există situații în care compilatorul are nevoie de informații suplimentare pentru a accepta schimbarea referinței pentru un obiect:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class MainClass{&lt;br /&gt;
&lt;br /&gt;
public static readChar(){&lt;br /&gt;
    //... reads a char from keyboard&lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
public static void main(String _args[]){&lt;br /&gt;
    Vehicle _vehicle;&lt;br /&gt;
    char c = readChar();&lt;br /&gt;
&lt;br /&gt;
    if(c == &amp;#039;a&amp;#039;){&lt;br /&gt;
        _vehicle = new Carriage(&amp;quot;green&amp;quot;, 2);&lt;br /&gt;
    }else{&lt;br /&gt;
        _vehicle = new Vehicle(&amp;quot;Scooter&amp;quot;, &amp;quot;red&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // this is called a down cast and it&amp;#039;s done&lt;br /&gt;
    // automatically (cast from Vehicle down to Object):&lt;br /&gt;
    Object _obj = _vehicle;&lt;br /&gt;
    // same with:&lt;br /&gt;
    _obj = (Object)_vehicle; &lt;br /&gt;
&lt;br /&gt;
    // the following does NOT work since the compiler does&lt;br /&gt;
    // not have enough information about the reference&lt;br /&gt;
    // _vehicle. What it knows for sure is that it refers to&lt;br /&gt;
    // an object of type Vehicle. It COULD be a Carriage, but&lt;br /&gt;
    // it doesn&amp;#039;t know:&lt;br /&gt;
    Carriage _carriage = _vehicle;&lt;br /&gt;
&lt;br /&gt;
    // so the programmer needs to explicitly tell the compiler &lt;br /&gt;
    // that the object is a Carriage, and this is called an&lt;br /&gt;
    // up cast (up from Vehicle to Carriage):&lt;br /&gt;
    Carriage _carriage = (Carriage)_vehicle;&lt;br /&gt;
    // however, _vehicle can still NOT be of type Carriage &lt;br /&gt;
    // (if char c is not &amp;#039;a&amp;#039;), and then a runtime exception&lt;br /&gt;
    // of type ClassCastException will be thrown&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;regula&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#ff0000&amp;quot;&amp;gt;Regulă:&amp;lt;/font&amp;gt; Up cast trebuie făcut întotdeauna explicit, indiferent cât de clar este tipul obiectului pentru programator:&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
String _someString = &amp;quot;Help!&amp;quot;;&lt;br /&gt;
Object _obj = _someString; //implicit down cast&lt;br /&gt;
String _otherString = (String)_obj; //explicit up cast&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mai mult despre polimorfism:&lt;br /&gt;
* http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html&lt;br /&gt;
&lt;br /&gt;
== Încapsulare ==&lt;br /&gt;
&lt;br /&gt;
Încapsularea se referă la modul de realizare a unei clase astfel încât implementarea să fie transparentă pentru utilizator. Astfel, elementele interne ale clasei sunt protejate la accesul neautorizat (încapsulate) și modificarea implementării nu influențează modul în care clasa este folosită în aplicații complexe.&lt;br /&gt;
&lt;br /&gt;
Ca exemplu pentru noțiunea de încapsulare, vom da ca exemplu o clasă &amp;#039;&amp;#039;&amp;#039;Sorter&amp;#039;&amp;#039;&amp;#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class Sorter{&lt;br /&gt;
&lt;br /&gt;
    private Comparable[] elements;&lt;br /&gt;
&lt;br /&gt;
public Sorter(Comparable[] _elements){&lt;br /&gt;
    elements = _elements;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public Comparable[] sort(){&lt;br /&gt;
    return bubbleSort();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
private Comparable[] bubbleSort(){&lt;br /&gt;
    Comparable[] _result = new Comparable[elements.length];&lt;br /&gt;
    System.arraycopy(_result, 0, elements, 0, _result.length);&lt;br /&gt;
    boolean _done;&lt;br /&gt;
    do{&lt;br /&gt;
        _done = true;&lt;br /&gt;
        for(int i=0; i&amp;lt;_result.length - 1; i++){&lt;br /&gt;
            if(_result[i].compareTo(_result[i + 1]) &amp;gt; 0){&lt;br /&gt;
                Comparable _temp = _result[i];&lt;br /&gt;
                _result[i] = _result[i + 1];&lt;br /&gt;
                _result[i + 1] = _temp;&lt;br /&gt;
                _done = false;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }while(!_done);&lt;br /&gt;
&lt;br /&gt;
    return _result;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Se observă că singurele metode publice sunt constructorul și metoda &amp;#039;&amp;#039;sort()&amp;#039;&amp;#039;. Astfel, implementarea efectivă a algoritmului de sortare este ascunsă. Dacă la un moment dat clasa &amp;#039;&amp;#039;&amp;#039;Sorter&amp;#039;&amp;#039;&amp;#039; va fi modificată astfel încât să folosească algoritmul Quick Sort în loc de Bubble Sort, orice clasă care folosește clasa &amp;#039;&amp;#039;&amp;#039;Sorter&amp;#039;&amp;#039;&amp;#039; va continua să funcționeze la fel ca și până atunci.&lt;br /&gt;
&lt;br /&gt;
=== Getters &amp;amp; Setters ===&lt;br /&gt;
&lt;br /&gt;
Un alt exemplu de încapsulare este practica de implementa pentru fiecare câmp câte două metode numite &amp;#039;&amp;#039;setter&amp;#039;&amp;#039; și &amp;#039;&amp;#039;getter&amp;#039;&amp;#039;. Motivul pentru această abordare este faptul că dacă un câmp este declarat public acesta poate fi modificat fără restricții de orice altă clasă. În schimb, dacă acest câmp are restricții, atunci acestea pot fi aplicate doar cu ajutorul unei metode. Vom da ca exemplu o clasă &amp;#039;&amp;#039;&amp;#039;Person&amp;#039;&amp;#039;&amp;#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class Person{&lt;br /&gt;
&lt;br /&gt;
    public static final boolean MALE = true;&lt;br /&gt;
    public static final boolean FEMALE = false;&lt;br /&gt;
&lt;br /&gt;
    private String fullName;&lt;br /&gt;
    private short age;&lt;br /&gt;
    private boolean gender;&lt;br /&gt;
&lt;br /&gt;
public Person(String _fullName, short _age, boolean _gender){&lt;br /&gt;
    setName(_fullName);&lt;br /&gt;
    setAge(_age);&lt;br /&gt;
    gender = _gender;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// setter method for field fullName&lt;br /&gt;
public void setName(String _fullName){&lt;br /&gt;
    // make use of regular expressions to check for&lt;br /&gt;
    // a valid name&lt;br /&gt;
    if(_fullName.matches(&amp;quot;[A-Z][a-zA-Z]+([ \\-][A-Z][a-zA-Z]+)+&amp;quot;)){&lt;br /&gt;
        fullName = _fullName;&lt;br /&gt;
    }else{&lt;br /&gt;
        throw new RuntimeException(&amp;quot;Invalid full name &amp;quot; + _fullName);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// setter method for field age&lt;br /&gt;
public void setAge(short _age){&lt;br /&gt;
    if(_age &amp;gt;= 0 &amp;amp;&amp;amp; _age &amp;lt;= 150){&lt;br /&gt;
        age = _age;&lt;br /&gt;
    }else{&lt;br /&gt;
        throw new RuntimeException(&amp;quot;Invalid age &amp;quot; + _age);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// setter method for field sex&lt;br /&gt;
public void setGender(boolean _gender){&lt;br /&gt;
    gender = _gender;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// getter method for field fullName&lt;br /&gt;
public String getName(){&lt;br /&gt;
    return fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// getter method for field age&lt;br /&gt;
public short getAge(){&lt;br /&gt;
    return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// getter method for field gender&lt;br /&gt;
public boolean getGender(){&lt;br /&gt;
    return gender;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Se observă că dacă accesul la cele două câmpuri &amp;#039;&amp;#039;fullName&amp;#039;&amp;#039; și &amp;#039;&amp;#039;age&amp;#039;&amp;#039; ar fi fost public, atunci acestea ar fi putut fi modificate cu orice valori invalide pentru scopul lor. Dar în acest fel, metoda &amp;#039;&amp;#039;setter&amp;#039;&amp;#039; verifică valoarea primită ca argument înainte de a fi atribuită câmpului.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;conventie&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#0000ff&amp;quot;&amp;gt;Convenție:&amp;lt;/font&amp;gt; Câmpurile unei clase se definesc private sau protejate, iar pentru cele se dorește acces public se implementează metode &amp;#039;&amp;#039;getter&amp;#039;&amp;#039; și &amp;#039;&amp;#039;setter&amp;#039;&amp;#039; publice.&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rhobincu</name></author>
	</entry>
</feed>