- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Hierarchical Inheritance in Dart Programming
Hierarchical inheritance is the case of inheritance when two classes inherit a single class.
The syntactic representation of a hierarchical inheritance looks something like this −
class A {} class B extends A {} class C extends A {}
In the above syntactic representation, we can see that two classes, namely B and C are inheriting (or extending) class A.
Example
Let's consider an example of hierarchical inheritance in dart. Consider the example shown below −
class Parent{ void printName(){ print("Inside class Parent"); } } class Daughter extends Parent{ void age(age){ print("Her age is: ${age}"); } } class Son extends Parent{ void name(name){ print("My name is: ${name}"); } } void main(){ Daughter d = new Daughter(); d.printName(); d.age(23); Son s = new Son(); s.printName(); s.name("Tuts"); }
In the above example, we have two classes, namely Son and Daughter that are extending the class named Parent.
Output
Inside class Parent Her age is: 23 Inside class Parent My name is: Tuts
Advertisements