Method Overriding & Super Keyword (OOPC - Part 07)
- JAVA Language -
Method Overriding
- Super Class එකකින් Sub Class එකකට ලබා ගන්න Method එකක Body එක වෙනස් කිරීම Method Overriding වේ.
- Method Overriding වලදී සෑම විටම ක්රියාත්මක වන්නේ Object එකට අදාල Method පමණයි
Output → Using Ladder!
Super = Parent
Sub = Child
-------------------------------------------------------------------------------------------------------
Super Keyword
- Sub Class එකක සිට Super Class එකේ Constructor එක Call කිරීමට Super Keyword එක භාවිතා කරයි.
- Super Keyword එකෙන් හැමවේලේම Call කරන්නේ Super Class එකට. Super Class එකේ Method සහ Variable සියල්ලම, Sub Class එකේ සිට Super Keyword එකෙන් Access කරන්න පුළුවන්.
Example Code :-
- Super(); → Super Class එකේ තිබෙන Methods සියල්ලම Run කරන එක සිදු කරයි.
- Super.climb(); / Super.climb(); → අදාල Method එකට පමණක් Call කරලා අදාල Method එක පමණක් Run කරන එක සිදු කරයි.
- See You in Part 8 -
😍Follow Me :-
Blog :- devindawanasinghe.blogspot.com
Facebook :- devindawanasinghe.facebook.com
YouTube :- devindawanasinghe.youtube.com
Twitter :- devindawanasinghe.twitter.com
TikTok :- devindawanasinghe.tiktok.com
Comments
Post a Comment