我最近学习了面向对象的python,并且在过去的几天里一直在努力学习Dart。但是,我在学习如何制作子类方面遇到了麻烦。
这是我想要在python中实现的结果:
class Employee:
def __init__(self, fistName, lastName, pay):
self.firstName = firstName
self.lastName = lastName
self.pay = pay
class Developer(Employee):
def __init__(self, firstName, lastName, pay, languages):
super().__init__(firstName, lastName, pay)
self.languages = languages
developer = Developer('John', 'Doe', 5000, ['Python', 'Java'])
在dart中,这是我到目前为止的代码:
class Employee {
String firstName;
String lastName;
num pay;
Employee(this.firstName, this.lastName, this.pay);
}
class Developer extends Employee{
List<String> languages;
Developer(?);
}
void main(){
var developer = new Developer('John', 'Doe', 5000, ['Python', 'Java'])
}
如何完成代码以便获得与python相同的结果?
答案 0 :(得分:1)
你可以这样做
class Employee {
String firstName;
String lastName;
num pay;
Employee(this.firstName, this.lastName, this.pay);
}
class Developer extends Employee{
List<String> languages;
Developer(String firstName, String lastName, num pay, this.languages): super(firstName, lastName, pay);
}
void main(){
var developer = new Developer('John', 'Doe', 5000, ['Python', 'Java']);
}