'what is the proplem in super method?
I have a problem in this code with dart:
void main() {
Mobile OPPO = Mobile(
color: 'yellow',
price: 5500,
);
OPPO.printColor();
OPPO.printPrice();
}
class Devices {
String? color;
int? price;
}
class Mobile extends Devices {
Mobile({
String? color,
int? price,
}) : super(color=color, price=price);
void printColor() {
print(color);
}
void printPrice() {
print(price);
}
}
lib/Test%20oop.dart:19:13: Error: Too many positional arguments: 0 allowed, but 2 found.
Try removing the extra positional arguments. }) : super(color=color, price=price);
^
Solution 1:[1]
Class Devices
missing constructor, dart meaning defaut Devices()
so it have no arguments but you passing 2. To fix this, create Devices
contructor with 2 arguments.
Addtional: super using :
not =
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Tuan |