OOPs Unit5 Questions Answers
OOPs Unit5 Questions Answers
Example:
class Car:
def __init__(self, brand):
self.brand = brand
def show(self):
print("Car brand is:", self.brand)
c = Car("BMW")
c.show()
Example:
class Animal:
def eat(self):
print("Animal eats")
class Dog(Animal):
def bark(self):
print("Dog barks")
d = Dog()
d.eat()
d.bark()
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()
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()
Example:
class Student:
def show(self):
print("I am a student")
s1 = Student() # s1 is an object
s1.show()
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()
class Mother:
def car(self):
print("Mother's car")
c = Child()
c.house()
c.car()