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 oop.dart:19:13: Error: Too many positional arguments: 0 allowed, but 2 found.
Try removing the extra positional arguments. }) : super(color=color, price=price);
^
CodePudding user response:
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 =
.