Last active
November 5, 2022 04:01
-
-
Save kwalrath/a98247f43448f5e0eac4c7f483c173a5 to your computer and use it in GitHub Desktop.
Java-to-Dart codelab: Starting Shapes example
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
import 'dart:math'; | |
abstract class Shape { | |
num get area; | |
} | |
class Circle implements Shape { | |
final num radius; | |
Circle(this.radius); | |
num get area => pi * pow(radius, 2); | |
} | |
class Square implements Shape { | |
final num side; | |
Square(this.side); | |
num get area => pow(side, 2); | |
} | |
main() { | |
final circle = Circle(2); | |
final square = Square(2); | |
print(circle.area); | |
print(square.area); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment