Abstract Class and Abstract Methods
Abstract Class & Abstract Methods
void main() {
// Abstract Class & Methods
var circle1 = Circle(3);
print(circle1.calarea());
}
abstract class Shape {
void draw();
double calarea();
}
class Circle extends Shape {
int radius;
final pi = 3.14;
@override
void draw() {
print("Drawing a Circle");
}
@override
double calarea() {
return (this.pi * this.radius * this.radius);
}
Circle(this.radius);
}
Abstract Class & Abstract Methods : Why do we use them ?
You can't declare an abstract method inside a simple class . You can only declare abstract methods inside abstract class
❌ Complier shows an error

✅ Compiler is happy

Abstract Class & Methods in Flutter
Official Documentation

Last updated
Was this helpful?