Test and review your Python OOP knowledge with practice questions on classes, objects, inheritance, polymorphism, encapsulation, and abstraction.
class Animal:
def speak(self):
print("Animal")
class Cat(Animal):
def speak(self):
print("Meow")
obj = Cat()
obj.speak()
def show(x):
print(x * 2)
show(5)
show("Hi")
class A:
def display(self):
print("A")
class B:
def display(self):
print("B")
def show(obj):
obj.display()
class Test:
def __init__(self, x):
self.x = x
def __add__(self, other):
return Test(self.x + other.x)
t1 = Test(10)
t2 = Test(20)
print((t1 + t2).x)