Abstract Classes and Abstract Methods
Define what subclasses must implement.
Abstract Classes and Abstract Methods is a free Dart Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Abstract Means
An abstract class is a blueprint you can describe but never create directly. It exists to be extended, not instantiated on its own.
Marking a Class Abstract
You add the abstract keyword before class. This tells Dart the class is incomplete and meant to serve as a shared base.
abstract class Shape {
double area();
}Abstract Methods Have No Body
An abstract method declares a name and signature but ends with a semicolon, leaving the actual work to each subclass.
abstract class Shape {
double area(); // no body
}You Cannot Instantiate It
Trying to write Shape() is a compile error. Dart refuses because an abstract class is unfinished and has no real implementation.
var s = Shape(); // error: abstractSubclasses Fill in the Blanks
A subclass uses extends and must provide a body for every abstract method, turning the blueprint into something usable.
class Circle extends Shape {
final double r;
Circle(this.r);
double area() => 3.14 * r * r;
}Concrete Methods Are Allowed Too
An abstract class can mix in fully written concrete methods. Subclasses inherit those directly and only fill the abstract ones.
abstract class Shape {
double area();
void describe() => print('Area is ' + area().toString());
}Fields in Abstract Classes
Abstract classes can hold fields and constructors too. They run when a subclass is created, so shared state lives in the base.
abstract class Shape {
final String name;
Shape(this.name);
}The Compiler Enforces the Contract
If a subclass forgets an abstract method, Dart reports an error before you ever run the code. The contract is checked for you.
class Square extends Shape {} // error: area() missingWhy Use Abstract Classes
They let many types share one shape while guaranteeing each provides its own behavior. You design a clear contract once and reuse it everywhere.
Abstract Getters
Methods are not the only things you can leave abstract. A getter with no body works the same way and must be defined by subclasses.
abstract class Shape {
String get label;
}Holding Abstract References
You can store any subclass in a variable typed as the abstract class. The type promises behavior without naming a concrete class.
Shape s = Circle(2);
print(s.area());Quick Check
One quick question about abstract classes.
Recap
Abstract classes are blueprints you extend, not instantiate. Abstract methods have no body, and concrete subclasses must implement them. Nice work! 🎯
Frequently asked questions
Is the “Abstract Classes and Abstract Methods” lesson free?
Yes — the full text of “Abstract Classes and Abstract Methods” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.
What will I learn in “Abstract Classes and Abstract Methods”?
Define what subclasses must implement. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Dart Academy?
No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Abstract Classes and Abstract Methods” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Dart Academy lesson?
Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Abstract Classes and Abstract Methods
- Implicit Interfaces and implements
- Polymorphism Through Shared Types
- Composition Over Inheritance