0% found this document useful (0 votes)
2 views3 pages

OOPs Inheritance Using Your Code

The document explains different types of inheritance in Object-Oriented Programming (OOP) using Python code examples. It covers Single, Multilevel, Hierarchical, Multiple, and Hybrid inheritance, demonstrating each type with class definitions and method calls. Each inheritance type showcases how classes can relate and share functionality in a structured manner.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

OOPs Inheritance Using Your Code

The document explains different types of inheritance in Object-Oriented Programming (OOP) using Python code examples. It covers Single, Multilevel, Hierarchical, Multiple, and Hybrid inheritance, demonstrating each type with class definitions and method calls. Each inheritance type showcases how classes can relate and share functionality in a structured manner.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

OOPs Inheritance Types using Given Code

1. Single Inheritance (stu -> test)

class stu:
def read(self):
print("Base class: Student")

class test(stu): # Single Inheritance


def getmarks(self):
print("Child class: Test")

s1 = test()
[Link]()
[Link]()

2. Multilevel Inheritance (stu -> test -> result)

class stu:
def read(self):
print("Base class: Student")

class test(stu):
def getmarks(self):
print("Child class: Test")

class result(test): # Multilevel Inheritance


def cal(self):
print("Sub-child class: Result")

s1 = result()
[Link]()
[Link]()
[Link]()

3. Hierarchical Inheritance (stu -> test and ass)

class stu:
def read(self):
print("Base class: Student")

class test(stu):
def getmarks(self):
print("Child class: Test")
class ass(stu):
def getgrade(self):
print("Child class: Assignment")

s1 = test()
s2 = ass()

[Link]()
[Link]()

[Link]()
[Link]()

4. Multiple Inheritance (test + ass -> res)

class test:
def getmarks(self):
print("Parent1: Test")

class ass:
def getgrade(self):
print("Parent2: Assignment")

class res(test, ass): # Multiple Inheritance


def cal(self):
print("Child class: Result")

s1 = res()
[Link]()
[Link]()
[Link]()

5. Hybrid Inheritance (stu -> test + ass -> res)

class stu:
def read(self):
print("Base class: Student")

class test(stu):
def getmarks(self):
print("Child class: Test")

class ass(stu):
def getgrade(self):
print("Child class: Assignment")
class res(test, ass): # Hybrid Inheritance
def cal(self):
print("Child class: Result")

s1 = res()
[Link]()
[Link]()
[Link]()
[Link]()

You might also like