Introduction to Abstract Classes and Methods
Learn about abstract classes and methods as well as non-abstract methods inside an abstract class.
We'll cover the following
We use abstract classes when we want to commit the programmer to write a certain class method, but we only know the name of the method without any details of how it should be written.
For example, circles, rectangles, and octagons may look different but are all 2-D shapes. This means they all have an area and a circumference. It makes sense, then, to group the code that they have in common into one parent class. In this parent class, we’ll have the area and circumference properties, and we may also have a method that calculates the area (this could be a problem though because different shapes require different calculations). Abstract classes are especially useful in such cases when we need to commit the child classes to certain methods that they inherit from the parent class but we don’t know how exactly that code will be used.
Get hands-on with 1400+ tech skills courses.