Skip to content

Instantly share code, notes, and snippets.

@mhmadip
Created April 15, 2022 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhmadip/92933fd4d4fb8051cb749efbaf1ce976 to your computer and use it in GitHub Desktop.
Save mhmadip/92933fd4d4fb8051cb749efbaf1ce976 to your computer and use it in GitHub Desktop.
This example shows inheritance in Dart
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