Advertisement
Hiteshw11

Class Inheritance In Dart

Nov 25th, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.90 KB | Source Code | 0 0
  1. /* Create a base class called Employee with properties name and salary, and a method displayDetails that prints the employee's details. Then, create a derived class called Manager that adds a property department and overrides the displayDetails method to include the department information. */
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8. void main()
  9. {
  10.   var n1=Employee('Alice',50000);
  11.   var n2=Manager('Bob',70000,'Sales');
  12.   print(n1.displaydetails());
  13.   print(n2.displaydetails());
  14. }
  15.  
  16. class Employee
  17. {
  18.   String name;
  19.   int salary;
  20.  
  21.   Employee(this.name,this.salary);
  22.  
  23.   String displaydetails()
  24.   {
  25.     return "Employee Name: ${name}, Salary: ${salary}";
  26.   }
  27.  
  28. }
  29.  
  30.  
  31. class Manager extends Employee
  32. {
  33.   String department;
  34.  
  35.   Manager(super.name,super.salary,this.department);
  36.  
  37.   @override
  38.   String displaydetails()
  39.   {
  40.     return "Manager Name: ${name}, Salary: ${salary}, Department: ${department}";
  41.   }
  42.  
  43. }
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement