I have to define a class Vehicle
. Each object of the class has two attributes, license
(license plate) and year
(year of construction), and two methods that return those attributes.
In addition, I have to define a class Car
, a derived class of Vehicle
, that has two more attributes, dis
(displacement) and max
(maximum number of people in the car), with methods to know the latter two.
This is the code I tried to write:
class vehicle:
def __init__(self,License_plate,Year):
self.license = License_plate
self.year = Year
def year(self):
return self.year
def license(self):
return self.license
class car(vehicle):
def __init__(self,License_plate,Year,Displacement,maximum):
veicolo.__init__(self, License_plate, Year)
self.dis = Displacement
self.max = maximum
def displacement(self):
return self.dis
def max(self):
return self.max
a = vehicle('ASDFE',1234) #This is how I tried to run it
a.year() #Here I got an ERROR :
a.license() #TypeError: 'int' object is not callable
b = car('ASDERTWWW',1234,7000,2340)
b.displacement()
b.max()
I have some problem with class in Python. I can not understand the use of a derived class.