<?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>super keyword &#8211; The SIGMA</title>
	<atom:link href="https://danushka96.github.io/sigma/index.php/tag/super-keyword/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>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>
	</channel>
</rss>
