# Inheritance and Polymorphism

## Inheritance:

```python
class Vehicle:
	
	vehicle_counter = 0
	
	def __init__(self, body_type, make):
		self.vehicle_body = body_type
		self.vehicle_make = make
		Vehicle.vehicle_counter += 1
		
	def get_vehicle_count(self):
		retunr Vehicle.vehicle_counter
		
class Truck(Vehicle):  
# By specifying Vehicle in parantheses the truck class iherits the propreties of the vehicle class

# So to create a truck you would use
truck1 = Truck('big rig', 'mercedes')
truck2 = Truck('small rig', 'Chevy')
truck3 = Truck('big rig', 'toyota')

truck3.get_vehicle_count # This gets the actual count of vehicles
```

* Based on the `Truck` class definition it is a `Vehicle`
* This increments the `Vehicle` counter accordingly
* `Truck` class must be used the same way as specified in the constructor of the `Vehicle` class
* `Truck` class inherits the `Vehicle` functionality

## Polymorphism (or Method Overwriting):

```python
class Vehicle:
	
	vehicle_counter = 0
	
	def __init__(self, body_type, make):
		self.vehicle_body = body_type
		self.vehicle_make = make
		Vehicle.vehicle_counter += 1
		
	def get_vehicle_count(self):
		retunr Vehicle.vehicle_counter
	
	def drive(self):
		print('vehicle driving...')

class Truck(Vehicle): # Inherits the Vehicle functionality
	def drive(self): # Overwrites the drive method from the Vehicle class
		print("Truck driving...") # By overwriting this prints specific instanced message instead
```

* The `Truck` class is also called a `child-class` or a `sub-class` of a `class`
* The `Vehicle` class is also called a `base-class` or a `parent-class`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.arkannis.net/programming/courses/python-pcap-31-03-course/modules-packages-and-oop/inheritance-and-polymorphism.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
