loading...

Inheritance in Dart: Part 4

kcooperdev profile image Khalif Cooper ・1 min read

This is part 4 of the object oriented programming series. We started in Part 1 with Classes and Object, then over to Part 2 with Abstraction, then the previous article with Polymorphism. This section will be super short as we have implemented inheritance indirectly in the previous articles. We will be going over the example and will wrap up from there.

Inheritance. What is Inheritance in programming? Inheritance is the process of inheriting or receiving features or methods from an existing class. In Abstraction we used inheritance, will we were extending the existing class and "inherited" some of the parent's class properties and methods.

An example of Inheritance:

class Car {
  void drive(){
    print("driving");
   }
}

class Honda extends Car{

}

  void main(){
   Honda car1 = new Honda();
  car1.drive();
  }

As you see in the example above; We create a new instance of the "Car" class(parent class). Next, we created a subclass(child class), with the class name of "Honda" and extend the "Car" class. Extending the "Car" class allows "Honda" to receive all the properties and features from the parent class. SIDE NOTE: Unlike polymorphism, inheritance does not change the behavior or functionality of the methods that the class inherits or receives.

Hope you enjoyed this article all about inheritance, until the next one...Stay Tuned..

Posted on Apr 13 by:

kcooperdev profile

Khalif Cooper

@kcooperdev

I am a developer passionate about learning and teaching others about code. I am all about JS and Dart.

Discussion

markdown guide