[go: up one dir, main page]

0% found this document useful (0 votes)
17 views1 page

Inheritance is a fundamental concept in object

Inheritance in object-oriented programming allows a subclass to inherit properties and methods from a superclass, enhancing code reusability and establishing hierarchical relationships. There are several types of inheritance: single, multiple, multilevel, hierarchical, and hybrid. An example in Python demonstrates a Dog class inheriting from an Animal class, showcasing the use of inherited and child class methods.

Uploaded by

Adarsh Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Inheritance is a fundamental concept in object

Inheritance in object-oriented programming allows a subclass to inherit properties and methods from a superclass, enhancing code reusability and establishing hierarchical relationships. There are several types of inheritance: single, multiple, multilevel, hierarchical, and hybrid. An example in Python demonstrates a Dog class inheriting from an Animal class, showcasing the use of inherited and child class methods.

Uploaded by

Adarsh Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Inheritance is a fundamental concept in object-oriented programming (OOP) that

allows a class (child or subclass) to inherit properties and behaviors (methods) from
another class (parent or superclass). It promotes code reusability and hierarchical
relationships.

Types of Inheritance

1. Single Inheritance – A child class inherits from a single parent class.

2. Multiple Inheritance – A child class inherits from multiple parent classes.

3. Multilevel Inheritance – A child class inherits from a parent class, which


itself is a child of another class.

4. Hierarchical Inheritance – Multiple child classes inherit from a single parent


class.

5. Hybrid Inheritance – A combination of different types of inheritance.

Example in Python

# Parent class

class Animal:

def speak(self):

print("Animal makes a sound")

# Child class inheriting from Animal

class Dog(Animal):

def bark(self):

print("Dog barks")

# Creating an object of Dog

d = Dog()

d.speak() # Inherited method

d.bark() # Child class method

You might also like