Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Create a base class `Shape` with a method `area` that returns 0. Create derived classes `Circle` and `Square` that override the `area` method to calculate the area of a circle and a square, respectively.
- #### Expected Output:
- ```dart
- Shape Area: 0
- Circle Area: 78.5
- Square Area: 25. */
- void main() {
- var a = Shape();
- print(a.area(3));
- var b = Circle();
- print(b.area(5));
- var c = Square();
- print(c.area(5));
- }
- class Shape
- {
- area(double s)
- {
- return s;
- }
- }
- class Circle extends Shape
- {
- Circle():super();
- @override
- area(data1)
- {
- double b =3.14*data1*data1;
- return b;
- }
- }
- class Square extends Shape
- {
- Square():super();
- @override
- area(data2)
- {
- double c = data2*data2;
- return c;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement