Two Classes. I have a new object in the parent class that gives attributes a value, and a calling method that displays them. Then I create a child class in a separate file and inherit from the parent class.
class Vehicle:
def __init__(self, brand, model):
self.brand = brand
self.model = model
def show_description(self):
print('Brand: ', self.brand, 'Model: ', self.model)
volvo = Vehicle('Volvo','L350H')
volvo.show_description()
#new class in separate file:
# ps. import not correct?
from vehicle import vehicle
class Excavator(Vehicle):
def __init__(self, brand, model):
super.__init__(brand, model)
hitachi = Excavator('Hitachi','EX8000')
hitachi.show_description()
Output: Brnad: Volvo Model: L350H
Brand: Hitachi Model: EX8000
Then I create object for Excavator class and I call show_description (). When I run the Excavator class file, it will also show me the print of the Vehicle, (Volvo). And my goal was to use the show_descriptipn () method - from Vehicle, only to display the new object (Hitachi) in the Excavator class. So, by calling a method from the parent class, we will get the result of both classes? We inherit everything, even the created objects? Or maybe I am doing something wrong in this case, or I don`t understand something. Could someone explain this?