Junior — Middle
Does Dart support the object-oriented programming paradigm?
sobes.tech AI
Answer from AI
Yes, Dart fully supports object-oriented programming (OOP). In Dart, everything is an object, including numbers, functions, and even null. The language supports the main principles of OOP: inheritance, encapsulation, and polymorphism.
Example of a class in Dart:
class Animal {
String name;
Animal(this.name);
void speak() {
print('$name makes a sound');
}
}
class Dog extends Animal {
Dog(String name) : super(name);
@override
void speak() {
print('$name says: Woof!');
}
}
void main() {
var dog = Dog('Bobby');
dog.speak(); // Outputs: Bobby says: Woof!
}