When inheriting an abstract class, a concrete child class must define the abstract methods, whereas an abstract class can extend another abstract class and abstract methods from the parent class don't have to be defined. Similarly, an interface extending another interface is not responsible for implementing methods from the parent interface.
When and why should abstract classes be used? I would like to see some practical examples of their uses. Also, what is the difference between abstract classes and interfaces?
The same case applies to abstract classes. Though we cannot create an object of an abstract class, when we create an object of a class which is concrete and subclass of the abstract class, the constructor of the abstract class is automatically invoked. Hence we can have a constructor in abstract classes.
For abstract methods you have to explicibly state it, yes. For virtual methods it is more complicated. If you don't state the override keyword there, the original method will become hidden. If this is your intention, you can use new keyword to get rid of the warning, but cases where you want to hide methods are pretty rare.
In the following code, I create a base abstract class Base. I want all the classes that inherit from Base to provide the name property, so I made this property an @abstractmethod. Then I created a
Abstract classes can be used to store methods in an OOP-based "library"; since the class doesn't need to be instantiated, and would make little sense for it to be, keeping common static methods inside of an abstract class is a common practice.
An abstract class cannot be instantiated by definition. In order to use this class, you must create a concrete subclass which implements all virtual functions of the class.
By adding the feature of abstract methods and types you prevent the unintended use of an incomplete type by someone who doesn't realize that it's incomplete. It provides a clear contract to sub-classes as to what functionality they need to provide, versus what methods of the base class are working but can optionally be extended.
Of course you can create an instance of a concrete class that inherits the abstract class, and such an instance can also be said to be an instance of the abstract class.