<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OOP &#8211; The SIGMA</title>
	<atom:link href="https://danushka96.github.io/sigma/index.php/category/oop/feed/" rel="self" type="application/rss+xml" />
	<link>https://danushka96.github.io/sigma/</link>
	<description>&#60;For Those Who Code/&#62;</description>
	<lastBuildDate>
	Sat, 02 Mar 2019 16:57:34 +0000	</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.1.1</generator>
	<item>
		<title>Interface</title>
		<link>https://danushka96.github.io/sigma/index.php/2018/04/13/interface/</link>
				<comments>https://danushka96.github.io/sigma/index.php/2018/04/13/interface/#respond</comments>
				<pubDate>Fri, 13 Apr 2018 04:38:20 +0000</pubDate>
		<dc:creator><![CDATA[Gayan Sampath]]></dc:creator>
				<category><![CDATA[OOP]]></category>
		<category><![CDATA[abstract class]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[final]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[static]]></category>

		<guid isPermaLink="false">https://danushka96.github.io/sigma/?p=855</guid>
				<description><![CDATA[<p><span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">3</span> <span class="rt-label rt-postfix">minutes</span></span> ආයුබෝවන් යාලුවවෝ හැමෝටම&#8230;oop පාඩම් මාලාවේ අවසන් පාඩමට ඔයාලා හැමෝම සාදරයෙන් පිලිගන්නවා&#8230;ඔයාලා දිගටම අපිත් එක්ක රැදී හිටියනම් මේ වෙනකොටත් oop වල තියන ගොඩක් දේවල් ඉගෙන ගෙන හමාරයි&#8230;oop වල මොකක් හරි පාඩමක් මග හැරුනනම් මෙතනින් ගිහින් බලන්න පුලුවන්&#8230;oop වල අවසාන්ම පාඩමෙන් මං කතා කරන්න බලාපොරොත්තු වෙන්නේ interface ගැන&#8230;පුරුදු විදියටම මුලින්ම මම කලින්<a class="moretag" href="https://danushka96.github.io/sigma/index.php/2018/04/13/interface/"> Read more&#8230;</a></p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/04/13/interface/">Interface</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></description>
								<content:encoded><![CDATA[<span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">3</span> <span class="rt-label rt-postfix">minutes</span></span><p><img class="alignnone size-medium wp-image-112" src="https://danushka96.github.io/sigma/wp-content/uploads/2018/03/oop-300x172.png" alt="" width="300" height="172" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/03/oop-300x172.png 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/03/oop.png 500w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>ආයුබෝවන් යාලුවවෝ හැමෝටම&#8230;oop පාඩම් මාලාවේ අවසන් පාඩමට ඔයාලා හැමෝම සාදරයෙන් පිලිගන්නවා&#8230;ඔයාලා දිගටම අපිත් එක්ක රැදී හිටියනම් මේ වෙනකොටත් oop වල තියන ගොඩක් දේවල් ඉගෙන ගෙන හමාරයි&#8230;oop වල මොකක් හරි පාඩමක් මග හැරුනනම් <a href="https://danushka96.github.io/sigma/index.php/category/oop/">මෙතනින්</a> ගිහින් බලන්න පුලුවන්&#8230;oop වල අවසාන්ම පාඩමෙන් මං කතා කරන්න බලාපොරොත්තු වෙන්නේ interface ගැන&#8230;පුරුදු විදියටම මුලින්ම මම කලින් පාඩම පොඩ්ඩක් මතක් කරලා ඉන්නම්කෝ&#8230;කලින් පාඩමේදී අපි කතා කලා abstract classes ගැන&#8230;body එකක් නැති එහෙමත් නැත්නම් meaningless body එකක් තියන method එකක් හරි ඊට වැඩි ගානක් හරි තියන class එකකට අපි කිව්වා abstract class එකක් කියලා&#8230;තව abstract class ගැන ගොඩක් විස්තර කතා කලා කලින් පාඩමේ..කලින් පාඩමේ තිබුන හැම දෙයක්මනම් මතක් කරන්න යන්නේ නෑ&#8230;අමතක නම් හරි අපෙ කලින් පාඩම බැලුවෙ නැත්තම් හරි මෙන්න <a href="https://danushka96.github.io/sigma/index.php/2018/04/12/abstract-class/">මෙතනින්</a> ගිහින් ඉක්මනට බලලා එන්නකෝ..</p>
<p>හරි එහෙනම් අපි දැන් බලමු අද පාඩම ගැන..අද පාඩම interface කියලා මම කලින් කිව්වනේ..හරි එහෙනන් අපි මුලින්ම බලමු interface එකක් කියන්නේ මොකද්ද කියලා&#8230;interface කියන්නේ මොකද්ද කියලා කියන්න කලින් මං කියන්නම් ඇයි interface පාවිච්චි කරන්නේ කියලා&#8230;.හරි අපි කලින් පාඩමකින් කතා කලානේ <a href="https://danushka96.github.io/sigma/index.php/2018/03/25/object-oriented-programming-5/" target="_blank" rel="noopener">inheritance</a> ගැන&#8230;එතනදී අපි කලේ එක class එකකින් තවත් class. එකක් inherit කරපු එකනේ&#8230;ඒ කියන්නේ එක inheritance එකයි තිබුනේ&#8230;multiple inheritance ගැන අපි කතා කලේ වත් නෑනේ නේද&#8230;එහෙම කලේ multiple inheritance java වල නැති නිසා&#8230;(C++ වල නම් තියනවා) &#8230;multiple inheritance කියන්නේ මේ වගේ එකකට&#8230;</p>
<pre>class A{

      // statement

}

class B{

    // statement

}

class C extends <strong>A,B</strong>{

     // statement

}

</pre>
<p>ඔන්න ඕකට තමයි multiple inheritance කියලා කියන්නේ&#8230;<strong>එක class එකක් class ගොඩකින් inherit වෙන එකට</strong>&#8230;ඔන්න ඔය දේ කරන්න java language එකේ ඉඩදෙන්නේ නෑ&#8230;අන්න ඒ දුර්වලතාව මගහැර ගන්න තමයි interface පාවිච්චි කරන්නේ&#8230;interface එක හැසිරීම class එකකට ගොඩක් දුරට සමානයි&#8230;නමුත් class එකක් නම් නෙවෙයි&#8230;interface වලින් පුලුවන් class කිහිපයක තියන ලක්ෂණ එක class එකකට ගන්න&#8230;හරියට නිකන් inheritance පාවිච්චි කලා වගේ..abstract class ගැන කතා කලා වගේම interface වල තියන ලක්ෂණ ටිකක් මුලින්ම මං කියන්නම්&#8230;</p>
<p>interface එකක් අපි define කරන්නේ interface කියලා දාලා interface එකේ නම ලියනවා..මෙන්න මේ විදියට..</p>
<pre>interface myInterface{

// statement

}
</pre>
<p>ඔන්න ඔහොමයි interface එකක් define කරන්නේ&#8230;</p>
<p>interface එකක තියෙන තවත් විශේෂත්වයක් තමයි interface එකක තියා ගන්න පුලුවන් abstract methods විතරයි.. interface එකක් ඇතුලේ තියා ගන්නේ abstract method විතරයිනම් interface එකත් abstract වෙන්න ඕනි නේද&#8230;.interface එක abstract වූනා කියන්නේ object හදන්නත් බැහැ &#8230;object හදන්න බෑ කියන්නේ constractor එකකුත් නෑ නේද.. තව දෙයක් තියනවා , interface එකක් ඇතුලේ තියන methods ඔක්කොම public වෙන්නත් ඕනි abstract වෙන්නත් ඕනි static වෙන්නත් ඕනි&#8230;ඒ වගේම interface එක ඇතුලේ තියන attributes ඔක්කොම public වෙන්නත් ඕනි static වෙන්නත් ඕනි final වෙන්නත් ඕනි..තවත් දෙයක් තීයනවා.intercace එකක reference variable එකකට පුලුවන් implements වුන class එකේ objects store කරගන්නත්..හරියට නිකන් මෙන්න මේ වගේ..</p>
<pre>interface A{
     // statement
}

class B implements A{
     //  statement
}

class Demo {
     public static void main(String a[]){
   
             interface A=new B() // upcasting 

     }

}
</pre>
<p>ඕන්න ඔය ටික තමයි interface එකක තියන ප්‍රධාන විශේෂත්ව&#8230;</p>
<p>හරි දැන් අපි බලමු interface පාවිචි කරන්නේ කොහොමද කියලා&#8230;කලින් මං කිව්වනේ interface කියන්නෙත් inheritance වගේ කියලා&#8230;inheritance වලදි නම් එක class එකකින් තවත් class එකක් inherit කරන්නේ extends keyword එක පාවිච්චි කරලනේ&#8230;interface එකක් නම් implements  keyword එක දාලා තමයි class එකට සම්බන්ද කරන්නේ&#8230;මේ විදියට interface ඕනි ගානකින් එක class එකක් imlements කරන්න පුලුවන්..</p>
<pre>interface A{

         abstract void a();          // abstract method of interface A..

}

interface B{

         abstract void b();         // abstract method of interface B..

}

class X{

        int x;

        void a(){

        // statement ;               // not an abstract method

        }

}

class Demo extends X implements A,B{

       // statements;

}
</pre>
<p>Demo class එක X ගෙන් inherit කරලා තියනවා, A හා B ගෙන් imlements කරලා තියනවා&#8230;හරි ඔන්න ඔය විදියට තමයි class එකක් interface එකකින් implements කරන්නේ..හරි තේරුනා නේද වැඩේ&#8230;.interface ගැන ඉතිං ඔච්චරයි කියන්න තියෙන්නේ😃😃😃&#8230;තේරුනා නේද අද පාඩම&#8230;.ඔන්න ඔය පාඩමත් සමගම අපේ oop පාඩම් මාලාවත් නිමාවෙනවා&#8230;oop වල මොකක් හරි අව්ලක් ආවොත් ඉක්මනට comment එකක් දාන්න&#8230;අපි සූදානම් ඔයාලට උදව් කරන්න..හරි එහෙනන් මට යන්න අවසරයි 😃😃😃&#8230;තවත් අලුත් පාඩම් මාලාවක් සමගින් ඉක්මනටම හමුවෙමු&#8230;ස්තූතියි !</p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/04/13/interface/">Interface</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></content:encoded>
							<wfw:commentRss>https://danushka96.github.io/sigma/index.php/2018/04/13/interface/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Abstract Class</title>
		<link>https://danushka96.github.io/sigma/index.php/2018/04/12/abstract-class/</link>
				<comments>https://danushka96.github.io/sigma/index.php/2018/04/12/abstract-class/#respond</comments>
				<pubDate>Thu, 12 Apr 2018 04:49:04 +0000</pubDate>
		<dc:creator><![CDATA[Gayan Sampath]]></dc:creator>
				<category><![CDATA[OOP]]></category>
		<category><![CDATA[abstract class]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[overriding]]></category>
		<category><![CDATA[super keyword]]></category>
		<category><![CDATA[this keyword]]></category>

		<guid isPermaLink="false">https://danushka96.github.io/sigma/?p=838</guid>
				<description><![CDATA[<p><span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">4</span> <span class="rt-label rt-postfix">minutes</span></span> ආයුබෝවන් ! oop පාඩම් මාලාවේ 11 වන දිගහැරුමත් සමග එකතු වෙන යාලුවෝ හැමෝම සාදරයෙන් පිලිගන්නවා&#8230;the sigma blog අඩවියත් සමග නිරන්තරයෙන් රැදී සිටි යාලුවෝ නම් මේ වෙනකොටත් object orianted programming ගැන ගොඩක් දේවල් ඉගෙනගෙන හමාරයි.ඔයා the sigma blog අඩවියට අලුත් සාමාජිකයෙක් නම් හරි , oop අව්ල් කෙනෙක් නම් හරි අපේ මුල්<a class="moretag" href="https://danushka96.github.io/sigma/index.php/2018/04/12/abstract-class/"> Read more&#8230;</a></p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/04/12/abstract-class/">Abstract Class</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></description>
								<content:encoded><![CDATA[<span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">4</span> <span class="rt-label rt-postfix">minutes</span></span><p><img class="alignnone size-medium wp-image-112" src="https://danushka96.github.io/sigma/wp-content/uploads/2018/03/oop-300x172.png" alt="" width="300" height="172" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/03/oop-300x172.png 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/03/oop.png 500w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>ආයුබෝවන් ! oop පාඩම් මාලාවේ 11 වන දිගහැරුමත් සමග එකතු වෙන යාලුවෝ හැමෝම සාදරයෙන් පිලිගන්නවා&#8230;the sigma blog අඩවියත් සමග නිරන්තරයෙන් රැදී සිටි යාලුවෝ නම් මේ වෙනකොටත් object orianted programming ගැන ගොඩක් දේවල් ඉගෙනගෙන හමාරයි.ඔයා the sigma blog අඩවියට අලුත් සාමාජිකයෙක් නම් හරි , oop අව්ල් කෙනෙක් නම් හරි අපේ මුල් පාඩම් ටික <a href="https://danushka96.github.io/sigma/index.php/category/oop/">මෙතනින්</a> ගිහින් බලන්න අමතක කරන්නත් එපා හොදේ. හරි එහෙනන් පටාන් ගමු අද පාඩම&#8230;අද පාඩම තමයි abstract class &#8230;. abstract class ගැන කතා කරන්න ඉස්සරින් කලින් පාඩම පොඩ්ඩක් මතක් කරන්නම්&#8230;කලින් පාඩමේදී අපි කතා කලා. encapsulation ගැන&#8230;මොකද්ද අපි encapsulation කියලා කිව්වේ&#8230; class එකක තියන data protect කරන එක එහෙමත් නැත්නම් data ආරක්ෂා කරන එකට අපි කිව්වා encapsulation කියලා&#8230;. අපේ encapsulation පාඩම මතක නැතිනම් <a href="https://danushka96.github.io/sigma/index.php/2018/04/11/encapsulation/">මෙතනින්</a> ගිහින් ඉක්මනට බලනකෝ&#8230;එතකොට සුපිරියටම මතක් වෙයි.</p>
<p>හරි එහෙනම් අපි දැන් බලමු අද පාඩම ගැන..අද පාඩම තමයි abstract class .<br />
abstract class එකක් ගැන කියන්න ඉස්සරින් මං කියන්නම් abstract method එකක් කියන්නේ මොකක්ද කියලා&#8230;ඇත්තටම abstract කියන වචනයෙන්ම කියවෙනවා නේද &#8220;මොකුත් නෑ/හිස්&#8221; වගේ අදහසක්&#8230;ඒකම තමයි මේ class වලත් විශේෂත්වය&#8230;හැබැයි පොඩ්ඩක් වෙනස්&#8230;ඇත්තටම abstract method එකක් කියන්නෙ body එකක් නැති  එහෙමත් නැත්නම් meaningless body එකක් තියන method එකකට&#8230;abstract method එකක් define කරන්නේ method එක ඉදිරියෙන් abstract කියන වචනය දාලා&#8230;හරියට නිකන් මෙන්න මේ වගේ&#8230;</p>
<pre>class Person {

     abstract void Jump(){

     }

}
</pre>
<p>ඔන්න ඔය විදියට තමයි abstract method එකක් define කරන්නේ&#8230;class එකක් ඇතුලේ ඔය වගේ abstract method එකක් හරි ඊට වැඩි ගානක් හරි තිබ්බොත් අන්න ඒ class එකත් abstract class එකක් වෙනවා&#8230; හරි එහෙනම් Person class එක ඇතුලෙ තියනවා නේද jump කියලා abstract method එකක් එහෙනම් අපේ Person class එකත් abstract වෙන්න ඕනි නේද&#8230;</p>
<pre>abstract class Person {

         abstract void Jump(){

      }

}
</pre>
<p>ඔන්න ඔය වගේ class වලට තමයි abstract class එකක් කියන්නේ&#8230;abstract class මොකටද ගන්නේ කියලා අපි පසුව බලමු&#8230;දැනට මතක තියාගන්නකෝ abstract class එකක් කියන්නේ ඕන්න ඕකකට කියලා ☺☺..</p>
<p>මේ abstract class ගත්තොත් විශේෂතා ගොඩක් තියනවා&#8230;.abstract method එකකනම් ඒකේ body එකේ මොකුත් තියා ගන්න බෑ &#8230;නමුත් abstract class එකක් ගත්තොත් ඒකේ abstract methods තියෙන්නත් පුලුවන් abstract නොවන methods තියෙන්නත් පුලුවන්&#8230;ඔන්න ඕක එක විශේෂත්වයක් abstract class වල තියෙන&#8230;තවත් දෙයක් තමයි මේ abstract class වලට objects හදන්න බෑ&#8230;.object හදන්න බැහැ කියන්නේ constructor එකකුත් නැහැ..ඔන්න ඕක තවත් විශේෂත්වයක්&#8230;පොඩ්ඩක් මේ උදාහරණය දිහා බලන්නකෝ&#8230;</p>
<pre>abstract class Person{

       abstract void jump();

       void run(){

       system.out.println(" i can run fast !");

       }

}

class Student extends Person{

       void study(){

       system.out.println("i am studding !");

       }

}
</pre>
<p>හරි එහෙනම් ඔය class දෙක දිහා හොදට බලන්නකෝ&#8230;Person class එකෙන් Student class එක inherit වෙලා තියනවා .. එහෙනම් Person class එකේ තියන privet නොවන සියලුම attributes හා methods Student class එක ඇතුලට එනවා නේද&#8230;ඒ කියන්නේ Person class එකේ තියන jump කියන abstract class එකත් Student class එක ඇතුලට ඇවිත් තියෙන්නේ&#8230;කලින් මං කිව්වනේ class එකක් ඇතුලේ අඩුම එක abstract method එකක්වත් තිබ්බොත් class එක abstract වෙනවා කියලා&#8230;.එහෙනම් අපේ Student class එකත් මෙන්න මේ වගේ abstract කරන්න ඕනි නේද&#8230;</p>
<pre>abstract class Person{

         abstract void jump();

         void run(){

         system.out.println(" i can run fast !");

         }

}

abstract class Student extends Person{

         void study(){

         system.out.println("i am studding !");

         }

}
</pre>
<p>හරි ඔන්න ඔහොම තමයි අපේ code එක එන්නේ&#8230;කිසි අව්ලක් නෑ&#8230;නමුත් මට ඕනි Student කෙනෙක්ගේ object එකක් හදන්න&#8230;Student class එක abstract එකක් නිසා මට Student කෙනෙක්ගෙ object එකක් හදන්න compiler එක ඉඩ දෙන්නේ නෑ&#8230;එහෙනම් කොහොමද මං Student කෙනෙක්ගේ object එකක් හදන්නේ&#8230;Student class එකේ තියන abstract කෑල්ල අයන් කරානම් හරි නේද &#8230;එහෙම කරන්නම් abstract methods class එකෙන් අයින් කරන්න ඕනි&#8230;Student Class එකේ තියන jump method එකනේ abstract method එකකට තියෙන්නේ&#8230;අන්න ඒ jump method එකේ abstract බව අයින් කලානම් හරි නේද&#8230;ඒ කියන්නේ jump method එක Student class එක ඇතුලෙදී override කලා නම් හරි නේද&#8230;<a href="https://danushka96.github.io/sigma/index.php/2018/03/31/method-overriding/">override</a> කලාම jump method එකට body එකක් තියන නිසා ඒ method එකේ abstract බව auto නැතිවෙලා යනවා &#8230;.code එක ලිව්වොත් මෙන්න මේ වගේ</p>
<pre>abstract class Person{

         abstract void jump();

         void run(){

         system.out.println(" i can run fast !");

         }

}

class Student extends Person{

       void jump(){   

       system.out.println("i can jump !");        // overriding the abstract class

       }

       void study(){

       system.out.println("i am studding !");

       }

}
</pre>
<p>හරි දැන් මට අව්ලක් නැතිව Student object එක හදන්න පුලුවන් නේද&#8230;&#8230;<br />
abstract class වල තියන තව විශේෂත්වයක් තමයි , abstract class reference variable එකකට පුලුවන් sub class objects store කර ගන්න..(upcasting)..අපේ උදාහරණයේ විදියටනම් මෙන්න මේ දේ&#8230;</p>
<pre>Person person1= new Student();
</pre>
<p>හරි ඔන්න ඔය ටික තමයි abstract class ගැන කියන්න තියෙන්නේ&#8230; interface වලදී abstract class හොදටම පාවිච්චි වෙනවා&#8230;එතකොට ඔයාලට තවත් හොදට තේරෙයි&#8230;</p>
<p>හරි අපි abstract class ගැන කතා කලානේ&#8230;දැන් මං කතා කරන්න හදන්නේ java වල තියෙන වැදගත් key word දෙකක් ගැන..කලින් අපි <a href="https://danushka96.github.io/sigma/index.php/2018/03/31/method-overriding/">super keyword</a> එක ගැනයි <a href="https://danushka96.github.io/sigma/index.php/2018/03/21/object-oriented-programming-4/">this keyword</a> එක ගැනයි කතා කලනේ..අද කතා කරන්න යන්නේ final keyword එක ගැනයි static keyword එක ගැනයි&#8230;</p>
<p>final keyword :</p>
<p>ඇත්තටම කියනවනම් final keyword එකෙන් කරන්නේ variable එකකට නිශ්චිත constant value එකක් assign කරන එක&#8230;උදාහරණයක් විදියට ගත්තොත් වෘත්තයක ව.ඵ හොයද්දි අපට ඕනි වෙන £ =3.14 කියන අගය&#8230;අපිට ඒක final keyword එක දාලා මේ විදියට define කෙරුව හැකි.</p>
<pre>final float £ = 3.14 ; 
</pre>
<p>ඔන්න ඕක තමයි final keyword එකෙන් කරන්නේ&#8230;</p>
<p>static keyword:</p>
<p>static keyword එකනම් ටිකක් වැදගත් keyword එකක්&#8230;අපිට static keyword එක දාලා attributes define කරන්නත් පුලුවන් methods define කරන්නත් පුලුවන්&#8230;attributes එකක් static කලොත් ඒ attribute එකේ value එක program එක අවසන් වුනත් නොවෙනස්ව පවත්වා ගන්න පුලුවන්..හරියට නිකන් මෙන්න මේ වගේ&#8230;</p>
<pre>class Cat{

     int age;

     static int numOfSibligs=0;

     void run(){

          System.out.print("it can be run fast !");

     }

}

Class Demo{

      public static void main(String a[]){

              Cat cat1= new Cat(); // creating a cat object

              numOfSibligs ++;

              System.out.println("cat1 has "+ cat1.numOfSibligs +" sibligs");

              Cat cat2= new Cat(); //creating another object

              numOfSibligs ++ ;

              System.out.println("cat2 has "+ cat2.numOfSibligs +" sibligs");

      }

}
</pre>
<p>සාමාන්‍ය variable එකක නම් object එක එක පාරක් හැදුවහම එහි අගය lost වෙලා යනවා. නමුත් static keyword එක පාවිච්චි කලොත් එහෙම වෙන්නෙ නැහැ . out put එකකවත් පොඩ්ඩක් බලන්නකෝ.</p>
<p>Out put :</p>
<p><img class=" wp-image-839 aligncenter" src="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/Capture1-300x154.jpg" alt="" width="565" height="290" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/Capture1-300x154.jpg 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/04/Capture1.jpg 610w" sizes="(max-width: 565px) 100vw, 565px" /></p>
<p>ඔන්න ඕකයි attribute එකක් static කලාම වෙන්නේ&#8230;දැන් අපි බලමු method එකක් static කලාම මොකද වෙන්නේ කියලා&#8230;ඇත්තටම method එකක් static කලාම , ඒ method එකට call කරන්න පුලුවන් object එකක් හදන්නේ නැතිව.ඒ කිව්වේ මෙන්න මේකයි.</p>
<pre>class Cat{

     int age;

     static int numOfSibligs=0;

     static void run(){

          System.out.print("it can be run fast !");

     }

}

class Demo{

      public static void main(String a[]){

              Cat.run();

              

      }

}
</pre>
<p>output :</p>
<p><img class=" wp-image-840 aligncenter" src="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/Capture2-300x144.jpg" alt="" width="544" height="261" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/Capture2-300x144.jpg 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/04/Capture2.jpg 526w" sizes="(max-width: 544px) 100vw, 544px" /></p>
<p>ඔන්න ඕක තමයි static keyword එකෙන් වෙන්නේ&#8230;</p>
<p>හරි අදට පාඩම හමාරි..😃😃&#8230;හැමෝටම තේරුනා කියලා හිතනවා&#8230;මොකක් හරි අව්ලක් තිබුනොත් පහලින් comment එකක් දාන්න&#8230;oop වල අවසාන පාඩමත් සමගින් හමුවෙමූ. සුභ දවසක් !</p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/04/12/abstract-class/">Abstract Class</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></content:encoded>
							<wfw:commentRss>https://danushka96.github.io/sigma/index.php/2018/04/12/abstract-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Encapsulation</title>
		<link>https://danushka96.github.io/sigma/index.php/2018/04/11/encapsulation/</link>
				<comments>https://danushka96.github.io/sigma/index.php/2018/04/11/encapsulation/#respond</comments>
				<pubDate>Wed, 11 Apr 2018 08:12:16 +0000</pubDate>
		<dc:creator><![CDATA[Gayan Sampath]]></dc:creator>
				<category><![CDATA[OOP]]></category>
		<category><![CDATA[access modifies]]></category>
		<category><![CDATA[encapsulation]]></category>
		<category><![CDATA[this keyword]]></category>

		<guid isPermaLink="false">https://danushka96.github.io/sigma/?p=802</guid>
				<description><![CDATA[<p><span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">4</span> <span class="rt-label rt-postfix">minutes</span></span> ආයුබෝවන් යාලුවන් හැමෝටම..object oriented consept එකේ මීලග පාඩමත් සමග එකතු වෙන යලුවන් හැමෝම සාදරයෙන් පිලිගන්නවා.අද පාඩමේදී මම කතා කරන්න බලාපොරොත්තු වෙනවා oop වල තියන අලුත්ම කොටසක් ගැන.ඒ තමයි encasulation.encapsulation ගැන කතා කරන්න ඉස්සරින් සපුරුදු විදියටම කලින් පාඩම පොඩ්ඩක් මතක් කරලා ඉන්නම්. කලින් පාඩමේදී අපි කතා කලේ polymorphsm ගැන &#8230;මොකද්ද අපි<a class="moretag" href="https://danushka96.github.io/sigma/index.php/2018/04/11/encapsulation/"> Read more&#8230;</a></p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/04/11/encapsulation/">Encapsulation</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></description>
								<content:encoded><![CDATA[<span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">4</span> <span class="rt-label rt-postfix">minutes</span></span><p><img class="alignnone size-medium wp-image-112" src="https://danushka96.github.io/sigma/wp-content/uploads/2018/03/oop-300x172.png" alt="" width="300" height="172" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/03/oop-300x172.png 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/03/oop.png 500w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>ආයුබෝවන් යාලුවන් හැමෝටම..object oriented consept එකේ මීලග පාඩමත් සමග එකතු වෙන යලුවන් හැමෝම සාදරයෙන් පිලිගන්නවා.අද පාඩමේදී මම කතා කරන්න බලාපොරොත්තු වෙනවා oop වල තියන අලුත්ම කොටසක් ගැන.ඒ තමයි encasulation.encapsulation ගැන කතා කරන්න ඉස්සරින් සපුරුදු විදියටම කලින් පාඩම පොඩ්ඩක් මතක් කරලා ඉන්නම්.</p>
<p>කලින් පාඩමේදී අපි කතා කලේ polymorphsm ගැන &#8230;මොකද්ද අපි poymorphsm කියලා කිව්වේ&#8230;poymorephsm කියලා අපි කිව්වේ, එක action එකක් කුම කිහිපයකින් කරන එකට නේද&#8230;polymorphsm ප්‍රධාන වශයෙන් compile time polymorephsm(static polymorphsm) හා run time polymorphm(dinamic method dispatch) කියලා කොටස් දෙකකට බෙදෙනවා කියලත් කිව්වා ..එක action එකක් method overloading පාවිච්චි කරලා ක්‍රම කිහිපයකින් කරන එකට අපි කිව්වා compile time poymorephsm (static poymorephsm) කියලා. run time polymorephsm එහෙමත් නැත්නම් dinamic method dispactch කියලා අපි කිව්වේ මොකද්ද&#8230;..run time poymorephsm එහෙමත් නැත්නම් dinamic method dispactch කියලා අපි කිව්වේ sub classes වල objects store කර ගන්න super class reference variable එකක් හදාගෙන ඒ හදාගත්තු reference variable එක පාවච්චි කරලා sub class වල තියන attributes හා methods වලට call කරන එකට.ඒ super class reference variable එක sub class objects store කරන්න තියන පොදු variable එකක් කියලත් අපි කිව්වා &#8230;හරි දැන් මතක් වුනා නේද polymorphsm ගැන&#8230;.තව දුරටත් විස්තර ඇතුව polymorphsm ගැන බලන්න ඕනි නම් <a href="https://danushka96.github.io/sigma/index.php/2018/04/06/polymorphism/" target="_blank" rel="noopener">මෙතනින්</a> අපේ කලින් පාඩමට ගිහින් බලලා එන්න&#8230;</p>
<p>හරි එහෙනන් අපි අද පාඩමට බහිමු.කලින් කිව්ව විදියට අද පාඩම encapsulation වුනාට java වල තියෙන පොඩි කොටසක් මං කලින්ම මතක් කරලා ඉන්නම්..එතකොට අද පාඩම තේරුම් ගන්න එක ටිකක් ලේසි වෙයි.. ඒ තමා access modifies . මේ ගැන නම් කතා කරන්න දේකුත් නෑ..මොකද අපි කලින් පාඩමකින් හොදටම කතා කලා මේක ගැන..ඒ වුනාට පොඩි සාරාංශයක් කරලා දාන්නම් &#8230;</p>
<p><img class="alignnone wp-image-803" src="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/Access-Modifiers-in-Java-300x102.png" alt="" width="576" height="196" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/Access-Modifiers-in-Java-300x102.png 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/04/Access-Modifiers-in-Java-768x262.png 768w, https://danushka96.github.io/sigma/wp-content/uploads/2018/04/Access-Modifiers-in-Java.png 1016w" sizes="(max-width: 576px) 100vw, 576px" /></p>
<p>ඔන්න ඕක තමයි access modifies ගැන කියන්න තියන සාරාංශ කතාව.තව දුරටත් අමතක වීමක් තියනවනම් <a href="https://danushka96.github.io/sigma/index.php/2018/03/18/object-oriented-programming/" target="_blank" rel="noopener">මෙතනින්</a> ගිහින් අපේ ඒ පාඩමත් බලන් එන්නකෝ&#8230;</p>
<p>හරි එහෙනම් අපි  බලමු   encapsulation කියන්නේ මොකක්ද කියලා. ඇත්තටම encapsulation වලින් කරන්නේ  class එකක තියෙන data protect  කරන එක. ඒ කියන්නේ class එක ඇතුලේ තියන attributes සහ methods ආරක්ෂා කරන එක. ගොඩක්  වෙලාවට අපි protect කරන්න ගන්නේ attributes තමයි.  .හරි එහෙනම් පුරුදු විදිහට මම උදාහරණයකින් පැහැදිලි කරන්නම්කො. මම ගන්නවා parson කියලා class එක. ඒකෙ attributes  තුනක් ගන්නවා මම ගන්නවා name , age සහ city  කියලා. හරි එහෙනම් අපි class  එක හදාගෙන ඉමුකො.</p>
<pre>class Person{
      String name;
      int age;
      String city;

}

</pre>
<p>හරි ඔන්න ඔය විදිහට නේද Person class එක එන්නේ. එහෙනම් අපි දැන් අපි parson ගෙ object එකකුත් හදාගෙන attributes වලට values assign කරමු.</p>
<pre>class Person{
      String name;
      int age;
      String city;

}

class Demo{
      public static void main(String a[]){

             Person person1=new Person();
             person1.name="john";
             person1.age=25;
             person1.city="Kandy";

             System.out.println("My name is :"+person1.name);
             System.out.println("My age is :"+person1.age);
             System.out.println("My city is :"+person1.city);
             
      }

}

</pre>
<p>හරි output එකක් බලන්නකෝ. කිසි අවුලක් නෑ නේද.</p>
<p><img class="alignnone wp-image-804" src="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/Capture-3-300x142.jpg" alt="" width="530" height="251" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/Capture-3-300x142.jpg 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/04/Capture-3.jpg 536w" sizes="(max-width: 530px) 100vw, 530px" /></p>
<p>පොඩ්ඩක් එහෙනම් බලන්නකෝ ඔයාලා හදපු person class එක දිහා. ඒකෙ තියන attributes ඔක්කොටොම කිසිම access modifier එක දාලා නෑ. ඒ කියන්නෙ ඒ හැම attribute එකක්ම default attribute එකක්. default නම් තමන්ගේ package එකේ ඔක්කොටම access කරන්න පුළුවන් නේ. ඒ නිසා තමයි අපි එළියේ(Demo)  class එකෙ  ඉදලා  person class ඒකෙ attributes වලට values assign  කරේ.  හරි දැන් එහෙනම් හිතලා බලන්නකෝ ඔය attributes ඔක්කොම private කළොත් මොකද වෙන්නේ කියලා.  private attributes වලට access කරන්න පුළුවන් තමන්ගේ class එකේ අයට විතරයි නේද&#8230; එහෙනම් කොහොමද අපි Demo class එකෙ ඉදලා මේ attributes වලට values assign කරන්නේ සහ ඒවා read කරන්නේ ?? අන්න එතකොට අපි  මේ attributes  වලට values assign කරන්න සහ ඒවා  read කරන්න පුළුවන් වෙන විදියට method හදාගන්නවා. හරි දැන් කියන්න බලන්න මේ methods  වල access  modifier එක මොන වගේ  එකක් වෙන්න ඕනෙද&#8230;method  වල access modifier එක private වුනොත් වැඩක් නැහැ නේද.. මොකද අපි මේ methods හදා ගත්තේ අර privet attributes ටිකට access කරන්නනේ&#8230;  එතකොට ඒ හදාගත්තු methods  ටිකත් private වුනොත්  ඒ methods   ටිකටත්  call කරන්න  බැරි වෙනවා නේද.. අන්න ඒ නිසා අපි හදාගන්න methods ටික public  උනානම් හරි. මොකද අපිට පුලුවන් එතකොට Demo class එකේ  ඉඳදලා public methods වලට call කරලා අර privet attributes ටිකට values assign  කරන්නයි  ඒවා  read කරන්නයි. මෙන්න මේ විදිහට private attributes වලට values assign හදන මේ .methodවලට අපි සාමාන්‍යයෙන් කියනවා getters සහ setters කියලා එහෙනම් අපි මේ getters සහ setters පාවිච්චි කරලා attributes වලට values assign කරන්නෙ කොහොමද කියලා බලමු.</p>
<pre>class Person{
     privet String name;
     privet int age;
     privet String city;
  
     public void setName(String name){
            this.name=name;            //  assign a name
     }
     
     public void setAge(int age){
            this.age=age;             // assign a age
     }

     public void setCity(String city){
            this.city=city;           // assign a sity
     }

     public void getName(){
            System.out.println("My name is :"+this.name);  //  getting the assigned name
     }

     public void getAge(){
            System.out.println("My age is :"+this.age);    // getting the assigned age
     }

     public void getCity(){
            System.out.println("My city is :"+this.city);  // getting the assigned city
     }
}

class Demo{
      public static void main(String a[]){

             Person person1=new Person();
             person1.setName("Smith");
             person1.setAge(20);
             person1.setCity("colombo");
             person1.getName();
             person1.getAge();
             person1.getCity();
             
      }

}

</pre>
<p>ඔන්න ඔය විදිහට තමයි getters සහ setters පාවිච්චි කරලා private attributes values sign කරන්නෙත් ඒව read කරන්නෙත්. this keyword එක පාවිච්චි කලේ ඇයි කියලා යාළුවෝ දන්නවනේ&#8230; මොකද අපි කලින් පාඩමක කතා කරලා තියනවා <a href="https://danushka96.github.io/sigma/index.php/2018/03/21/object-oriented-programming-4/" target="_blank" rel="noopener">this keyword</a> එක ඇයි පාවිච්චි කරන්නේ කියලා.අපි මේ කරපු දේ ගැන කෙටියෙන් කියනවා නම් , මෙයින් කරලා තියෙන්නේ class එකක තියන data වලට access කරන එක සීමා කිරීම්යි. තවත් විදියකින් කියනවා නම් class data වලට access කරන එක සීමා කරලා data protect කිරීමයි . ඔන්න ඔය සරල ක්‍රියාවලියට තමයි encapsulation කියලා කියන්නේ. හරි අද පාඩම තේරුනා කියලා හිතනවා. මොකක් හරි අවුලක් ආවොත් comment එකක් දාන්න මීළඟ පාඩමෙන් හමුවෙමු. සුබ දවසක්!</p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/04/11/encapsulation/">Encapsulation</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></content:encoded>
							<wfw:commentRss>https://danushka96.github.io/sigma/index.php/2018/04/11/encapsulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
	</channel>
</rss>
