Inheritance Introduction.py

# Inheritance is the capability of one class
# to derive or inherit the properties from another class

class information :
def __init__(self, name, age, phone):
self.name = name
self.age = age
self.phone = phone

def write(self):
print("Name :: ", self.name)
print("Age :: ", self.age)
print("Phone :: ", self.phone)

class student(information) :
pass

std1 = student("Aubdur Rob Anik", 14, "01685946475")
std1.write()

### Add Properties in Child Class
class data :
def __init__(self, name, occupation, age):
self.name = name
self.occupation = occupation
self.age = age

class person(data) :
print("\nHe/She is an Bangladeshi")
def Data_Print(self):
print("Name :: ", self.name)
print("Occupation :: ", self.occupation)
print("Age :: ", self.age)

p1 = person("Aubdur Rob Anik", "Student", 14)
p1.Data_Print()

### Called method from parent class
class people :
def __init__(self, name, age, phone):
self.name = name
self.age = age
self.phone = phone

def write(self):
print("\nName :: ", self.name)
print("Age :: ", self.age)
print("Phone :: ", self.phone)

class student_Bio(people) :
def __init__(self, name, id, age, phone, university):
people.__init__(self, name, age, phone)
self.id = id
self.university = university

def printAll(self):
people.write(self)
print("ID :: ", self.id)
print("University :: ", self.university)

std1 = student_Bio("Aubdur Rob Anik", 73, 14, "01685946475", "UAP")
std1.printAll()

Comments