import 'dart:math';
void main() {
// Abstract Class & Methods
// You can't make an instance of an abstract class
// Abstract class always meant to extended by some other class
// When any class extend an abstract , it must override it's
// abstract methods
var circle1 = Circle(3);
var square1 = Square(3);
print(circle1.calarea());
print(square1.calarea());
}
abstract class Shape {
void test() {
print("test");
}
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);
}
class Square extends Shape {
double length;
@override
void draw() {
print("Drawing a Square");
}
@override
double calarea() {
return pow(this.length, 2);
}
Square(this.length);
}
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
You can have an abstract class with only normal methods , but that defeats the purpose of using an abstract class