Inheritance in Dart

in CCS2 days ago (edited)

Hello everyone!

Today I am here to share another concept Inheritance in Object Oriented Programming (OOP) in dart.


inheritance (2).png

Designed with Canva

Inheritance is an important concept in OOP. It directly relates with the inheritance in real life. We see that the children inherits properties from their parents. Similarly in programming the child classes inherits some properties from the parent/super/base class. The parent class allows its child classes to get properties from that class.


image.png

I have created a parent class Person. Now I will get properties from this class. It has a variable name, a constructor to initialize the name and a method introduce().


image.png

I have created a child classStudent which uses extends keyword to access parent class Person and gets its properties. The student class has its own unique attribute ofrollno` as well.


image.png

This is the main where I have created the object of the student . The constructor was called and I provided it name. Then I have called function introduce() using this object from the parent class and it worked and did not show any error or problem.


image.png

Here you can see the complete program and the output of the program. The program worked very well and the child class successfully inherited the properties from the parent class.

This is how inheritance works. Later on I will share more about this concept with more complex examples.

Posted using SteemX

Sort:  

🎉 Congratulations!

Your post has been upvoted by the SteemX Team! 🚀

SteemX is a modern, user-friendly and powerful platform built for the Steem community.

🔗 Visit us: www.steemx.org

✅ Support our work — Vote for our witness: bountyking5

banner.jpg