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

OOPs Unit5 Questions Answers

The document provides an overview of Object-Oriented Programming (OOP) concepts, including its features such as classes, inheritance, polymorphism, encapsulation, and abstraction. It explains key concepts with examples, such as method overriding and different types of inheritance in Python. Each concept is illustrated with code snippets to enhance understanding.

Uploaded by

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

OOPs Unit5 Questions Answers

The document provides an overview of Object-Oriented Programming (OOP) concepts, including its features such as classes, inheritance, polymorphism, encapsulation, and abstraction. It explains key concepts with examples, such as method overriding and different types of inheritance in Python. Each concept is illustrated with code snippets to enhance understanding.

Uploaded by

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

Python Unit 5 - OOPs Important Questions and Answers

Q1. What is OOP? Explain its features.


Answer:
OOP (Object-Oriented Programming) is a programming method where programs are
designed using objects, which combine data and functions.
Features of OOP:
1. Class and Object – Class is a blueprint, object is an instance.
2. Inheritance – Ability to inherit properties from parent class.
3. Polymorphism – Same method behaving differently.
4. Encapsulation – Wrapping data and methods into a single unit.
5. Abstraction – Hiding complex details and showing only necessary parts.

Example:
class Car:
def __init__(self, brand):
self.brand = brand

def show(self):
print("Car brand is:", self.brand)

c = Car("BMW")
c.show()

Q2. What is Inheritance? Explain with example.


Answer:
Inheritance is an OOP feature where a class (child) can use properties and methods
of another class (parent).
It provides code reusability.

Example:
class Animal:
def eat(self):
print("Animal eats")

class Dog(Animal):
def bark(self):
print("Dog barks")

d = Dog()
d.eat()
d.bark()

Q3. What is Polymorphism? Explain with example.


Answer:
Polymorphism means many forms.
In Python, it allows the same method name to perform different actions, depending
on the object.

Example:
class Bird:
def sound(self):
print("Some bird sound")

class Sparrow(Bird):
def sound(self):
print("Chirp Chirp")

b = Bird()
s = Sparrow()

b.sound()
s.sound()

Q4. Explain Polymorphism with Inheritance with example.


Answer:
When a child class overrides a method of parent class, it's called polymorphism
with inheritance.

Example:
class Shape:
def area(self):
print("Area not defined")

class Circle(Shape):
def area(self):
print("Area of Circle is πr²")

class Square(Shape):
def area(self):
print("Area of Square is side²")

c = Circle()
s = Square()

c.area()
s.area()

Q5. What is the difference between class and object?


Answer:
Class: A blueprint or template that defines properties (variables) and behaviors
(methods).
Object: An instance of a class, which can access data and methods of the class.

Example:
class Student:
def show(self):
print("I am a student")

s1 = Student() # s1 is an object
s1.show()

Q6. Explain method overriding with example.


Answer:
Method overriding occurs when a child class provides a specific implementation of a
method that is already defined in its parent class.

Example:
class Vehicle:
def start(self):
print("Vehicle is starting")
class Car(Vehicle):
def start(self):
print("Car is starting with key")

c = Car()
c.start()

Q7. Explain types of inheritance in Python.


Answer:
1. Single Inheritance: One child class inherits from one parent class.
2. Multiple Inheritance: One child class inherits from more than one parent class.
3. Multilevel Inheritance: Child class inherits from parent, and another child
class inherits from that child.
4. Hierarchical Inheritance: Multiple child classes inherit from a single parent
class.

Example (Multiple Inheritance):


class Father:
def house(self):
print("Father's house")

class Mother:
def car(self):
print("Mother's car")

class Child(Father, Mother):


pass

c = Child()
c.house()
c.car()

You might also like