Created
April 15, 2022 14:21
-
-
Save mhmadip/92933fd4d4fb8051cb749efbaf1ce976 to your computer and use it in GitHub Desktop.
This example shows inheritance in Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product{ | |
String _name; | |
num _price; | |
String _expDate; | |
Product(this._name,this._price,this._expDate); | |
void printDetails(){ | |
print('Name: $_name'); | |
print('Price: $_price'); | |
print('Expire: $_expDate'); | |
} | |
} | |
class Beverage extends Product{ | |
num _liters; | |
String _type; | |
Beverage(String name, num price, String expDate, this._liters,this._type): | |
super(name,price,expDate); | |
void beverageDetails(){ | |
printDetails(); | |
print('Liters: $_liters'); | |
print('Type: $_type'); | |
} | |
} | |
void main(){ | |
var drink = Beverage('Cola', 1.50, '1/1/2022', 1, 'soft drink '); | |
drink.beverageDetails(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment