gpt4 book ai didi

python - 如何在 Dart 中正确使用子类的 super 方法?

转载 作者:行者123 更新时间:2023-12-01 09:23:07 25 4
gpt4 key购买 nike

最近学习了面向对象的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 中相同的结果?

最佳答案

你可以这样做

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']);
}

关于python - 如何在 Dart 中正确使用子类的 super 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50650459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com