Python Programming - Inheritance
Exercise : Inheritance - General Questions
- Inheritance - General Questions
66.
How can you achieve method overloading?
Answer: Option
Explanation:
Python does not support method overloading in the traditional sense as it is done in languages like Java. Methods with the same name in a class will override each other.
67.
Consider the following code:
class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
def speak(self):
print("Dog barks")
def main():
my_pet = Dog()
my_pet.speak()
What will be the output of the main()
function?
Answer: Option
Explanation:
The
speak()
method is overridden in the Dog
class, so calling speak()
on a Dog
instance will print "Dog barks".
68.
What is the purpose of the
issubclass()
function?
Answer: Option
Explanation:
The
issubclass()
function is used to check if a class is a subclass of another class.
69.
Consider the following code:
class A:
def method(self):
print("Method in class A")
class B(A):
def method(self):
print("Method in class B")
class C(B):
pass
obj = C()
obj.method()
What will be the output of the obj.method()
call?
Answer: Option
Explanation:
The
method()
is overridden in class B, and since class C inherits from class B, calling obj.method()
will print "Method in class B".
70.
How does Python handle multiple inheritance conflicts for method resolution?
Answer: Option
Explanation:
Python uses the C3 linearization algorithm to determine the method resolution order in case of conflicts in multiple inheritance.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers