Abstract Classes and Abstract Methods in Dart
Tags: dart, todayilearned, beginners
Published: 2019-09-16 04:48:35

* An abstract class is a type of class that cannot be instantiated directly which means an object cannot be created from it.
    
* An abstract class cannot be instantiated but they can be sub-classed.

* To define an abstract class we use ***abstract*** keyword.

####The syntax for defining Abstract Class

```dart
abstract class class_name {
  // Body of abstract class
}
```

##Abstract Methods
***

* Abstract methods can only exist within an abstract class.
* To make a method abstract, use a semicolon (;) instead of the method body.

```dart
void talk (); // Abstract method
void walk (); // Abstract method
```

* Normal classes can extend the abstract class, but they have to override every abstract method.
* You can also create normal methods in the abstract class. And to override normal method is not mandatory.
* The abstract class will only complain when you don’t override the abstract method.

####Sample Code

```dart
abstract class Person{
void walk();  //Abstract Method
  void talk();  //Abstract Method
}
class Jay extends Person{
  @override
  void walk() {
    print("Jay can walk");
  }
@override
  void talk() {
    print("Jay can talk");
  }
}
main(){
  Jay jay = new Jay();
jay.talk();
  jay.walk();
}

Output
Jay can talk
Jay can walk
```

##Difference between Abstract class and Interface
***

* So now after seeing both abstract class and interface. You might ask that technically they look the same. Ya, that’s true that they are closely related. But guys they are not exactly the same. Let’s understand the basic difference between them.

![](https://miro.medium.com/max/758/1*1MKQuaHFnM8n_ZfHu6rEbQ.jpeg)


So, guys, that’s it for abstract classes. Feel free to tell me if I miss something, I’ll love to learn it from you. Till then Keep Loving, Keep Coding. And Just like always I’ll catch you up in the next article.

Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitate that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.

###For More Information Please Visit Following Links
* [Fuchsia OS official site](https://fuchsia.dev/)
* [Dart official site](https://dart.dev/)
* [Flutter official site](https://flutter.dev/)


Jai Hind, Vande Mataram 🇮🇳

Wanna get in touch with me? Here are links. I’ll love to become your friend. 😊

- [My Site] (https://www.jaytillu.in)
- [My Blogs] (https://blogs.jaytillu.in)
- [Twitter](https://twitter.com/jay_tillu)
- [Facebook](https://www.facebook.com/jaytillu.1314/)
- [Instagram](https://www.facebook.com/jaytillu.1314/)
- [Medium](https://medium.com/jay-tillu)
- [LinkedIn](https://www.linkedin.com/in/jaytillu/)
- [Github](https://www.github.com/jay-tillu)
- [Stack overflow](https://stackoverflow.com/users/8509590/jay-tillu)
or just mail me at jd.tillu@gmail.com