Solution: Create an Abstract Class and Derive Classes from It
Learn how to create the abstract class Vehicle, derive two classes from it, and then call the methods using objects of derived classes.
We'll cover the following...
The solution to the problem of creating the abstract class Vehicle
, deriving two classes from it, and then calling the methods using objects of derived classes is given below.
Solution
Press + to interact
from abc import ABC, abstractmethodclass Vehicle(ABC) :@abstractmethoddef speed(self) :passdef maintenance(self) :passdef value(self) :passclass FourWheeler(Vehicle) :def speed(self) :print('In FourWheeler.speed')def maintenance(self) :print('In FourWheeler.maintenance')def value(self) :print('In FourWheeler.value')class TwoWheeler(Vehicle) :def speed(self) :print('In TwoWheeler.speed')def maintenance(self) :print('In TwoWheeler.maintenance')def value(self) :print('In TwoWheeler.value')# v = Vehicle( ) # will result in error, as Vehicle is abstract classfw = FourWheeler( )fw.speed( )fw.maintenance( )fw.value( )tw = TwoWheeler( )tw.speed( )tw.maintenance( )tw.value( )