Code Samples- Python OOP
Code Samples- Python OOP
# define a class
class Bike:
name = ""
gear = 0
# create a class
class Room:
length = 0.0
breadth = 0.0
1. Example of inheritance
class Animal:
# attribute and method of the parent class
name = ""
def eat(self):
print("I can eat")
# Polymorphism
class Car:
def __init__(self, brand, model):
self.brand = brand
self.model = model
def move(self):
print("Drive!")
class Boat:
def __init__(self, brand, model):
self.brand = brand
self.model = model
def move(self):
print("Sail!")
class Plane:
def __init__(self, brand, model):
self.brand = brand
self.model = model
def move(self):
print("Fly!")