Intermediate Dart
  • Welcome to the Course
  • Course Overview
  • Resources
  • Dart Fundamentals-2
    • Section Overview
    • Basic Concepts
      • Class
      • Object/Instance
      • Instance /Field Variables
      • Methods
      • "this" keyword-1
    • Constructor
      • Default Constructor
      • Parameterised Constructor
        • Basic Parameterised Constructor & "this" keyword -2
        • Parameterised Constructor with Syntactic sugar
        • Optional Arguments in Parameterised Constructor
      • Named Constructor
    • Getters & Setters and Encapsulation
      • Access Modifiers and _ symbol
      • Implicit / Default Getters & Setters
      • Custom Getters and Setters
      • Encapsulation
    • Inheritance
      • Inheritance, Types of Inheritance , Terminology
      • Method Overriding
      • @override annotation
      • super Keyword -1
      • super Keyword -2
    • Polymorphism
    • Static Variables and Methods
    • Abstract Class and Abstract Methods
    • Interface
    • Miscellaneous concepts
      • Untitled
      • Object Class
      • Mixin
      • Immutable Instances
      • Cascade notation
  • Dart Fundamentals -3
    • Section Overview
    • Asynchronous Programming
      • Basic Concept of Asynchronous programming
      • async , await , then
      • Exception Handling in asynchronous code
    • Functional Programming
      • Anonymous functions
      • High Level Iterators
    • Advanced Asynchronous Programming
      • Isolates
      • Streams
      • Generators
      • Microtask and Zones
    • Method & Constructor Overloading
Powered by GitBook
On this page
  • Basic concept of Inheritance
  • Types of Inheritance & Terminology
  • Coding Example

Was this helpful?

  1. Dart Fundamentals-2
  2. Inheritance

Inheritance, Types of Inheritance , Terminology

PreviousInheritanceNextMethod Overriding

Last updated 4 years ago

Was this helpful?

Basic concept of Inheritance

You can inherit all the properties and methods of a class by using "extends" keyword

Types of Inheritance & Terminology

Dart doesn't support multiple inheritance .If you want to know why, Google "Deadly Diamond of Death"

Coding Example

void main() {
  // Inheritance Example

  var developer1 = Developer();

  var manager1 = Manager();
  

  developer1.id = 1;

  developer1.firstname = "John";

  developer1.lastname = "Doe";

  developer1.dayworked = 12;
  
  
  
  developer1.proglanguage = "Dart";
  
  
  

  manager1.id = 2;

  manager1.firstname = "Jane";

  manager1.lastname = "Doe";

  manager1.dayworked = 12;
  
  
  
  manager1.project = "Alpha";
  

  print(developer1.id);
  print(developer1.firstname);
  print(developer1.lastname);
  print(developer1.dayworked);
  print(developer1.fullname());
  print(developer1.salary(20));
  
  print(developer1.coding());

  print("------------");

  print(manager1.id);
  print(manager1.firstname);
  print(manager1.lastname);
  print(manager1.dayworked);
  print(manager1.fullname());
  print(manager1.salary(20));
  
  
  print(manager1.manageproject());
  
  
  
}

class Employee {
  int id;
  int dayworked;
  String firstname;
  String lastname;

  String fullname() {
    return this.firstname + " " + this.lastname;
  }

  int salary(int perDaywage) {
    return (this.dayworked * perDaywage);
  }
}





// Developer Class 


class Developer extends Employee {
  
  //property 
  
  String proglanguage;
  
  
 // Method 

  String coding() {
    return "Coding in " + " " + this.proglanguage;
  }
}




// Manager Class 


class Manager extends Employee {
  
  
  //property 
   String project;
  
  
  
  //Method 
  
  String manageproject(){
    
    return "Managing project " + " " + this.project;
    
    
    
  }
  
  
  
  
  
}

Note: There is a typo . Used "manager1.dayworked = 12" instead of

"manager1.dayworked = 10"