Chapter folders renamed

This commit is contained in:
Karan Solanki
2021-08-13 11:44:51 +05:30
parent d9f3f5b159
commit 1eb709f83a
211 changed files with 0 additions and 0 deletions
@@ -0,0 +1,17 @@
#methodoverloading1.py
class Car:
def __init__(self, color, seats):
self.i_color = color
self.i_seat = seats
def print_me(self, i='basic'):
if(i =='basic'):
print(f"This car is of color {self.i_color}")
else:
print(f"This car is of color {self.i_color} with seats {self.i_seat}")
if __name__ == "__main__":
car = Car("blue", 5 )
car.print_me()
car.print_me('blah')
car.print_me('detail')
@@ -0,0 +1,31 @@
#methodoverriding1.py
class Vehicle:
def __init__(self, color):
self.i_color = color
def print_me(self):
print(f"This is vehicle and I know my color is {self.i_color}")
class Car (Vehicle):
def __init__(self, color, seats):
self.i_color = color
self.i_seats = seats
def print_me(self):
print( f"Car with color {self.i_color} and no of seats {self.i_seats}")
class Truck (Vehicle):
def __init__(self, color, capacity):
self.i_color = color
self.i_capacity = capacity
def print_me(self):
print( f"Truck with color {self.i_color} and loading capacity {self.i_capacity} tons")
if __name__ == "__main__":
vehicle = Vehicle("red")
vehicle.print_me()
car = Car ("blue", 5)
car.print_me()
truck = Truck("white", 1000)
truck.print_me()