Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 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. */
- void main()
- {
- var n1=Employee('Alice',50000);
- var n2=Manager('Bob',70000,'Sales');
- print(n1.displaydetails());
- print(n2.displaydetails());
- }
- class Employee
- {
- String name;
- int salary;
- Employee(this.name,this.salary);
- String displaydetails()
- {
- return "Employee Name: ${name}, Salary: ${salary}";
- }
- }
- class Manager extends Employee
- {
- String department;
- Manager(super.name,super.salary,this.department);
- @override
- String displaydetails()
- {
- return "Manager Name: ${name}, Salary: ${salary}, Department: ${department}";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement