Question 21
EasyIn Python, what is the MRO?
- A.
The memory reuse option
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
In Python, what is the MRO?
The memory reuse option
The main return object
A type of loop
The method resolution order: the order in which classes are searched for a method
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class A:
def hi(self):
return "A"
class B(A):
pass
print(B().hi())
B
A
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class A:
def name(self):
return "A"
class B(A):
def name(self):
return "B"
print(A().name() + B().name())
AB
BA
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class A:
def __init__(self):
self.x = 1
class B(A):
def __init__(self):
super().__init__()
self.y = 2
b = B()
print(b.x + b.y)
12
2
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
#include <iostream>
using namespace std;
class A {
public:
A() { cout << "A"; }
};
class B : public A {
public:
B() { cout << "B"; }
};
int main() {
B b;
}
A
B
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
#include <iostream>
using namespace std;
class A {
public:
~A() { cout << "A"; }
};
class B : public A {
public:
~B() { cout << "B"; }
};
int main() {
B b;
}
A
B
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class Animal:
pass
class Dog(Animal):
pass
print(isinstance(Dog(), Animal))
True
Dog
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class Animal:
def speak(self):
return "Some sound"
class Dog(Animal):
def speak(self):
return "Woof"
print(Dog().speak())
Error
Some sound Woof
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class Animal:
def speak(self):
return "Some sound"
class Dog(Animal):
def speak(self):
return super().speak() + " Woof"
print(Dog().speak())
Woof
Some sound
Sign up free to see the answer and a step-by-step explanation.
What is the diamond problem in multiple inheritance?
A class can't be instantiated
A class inherits the same base class through two paths, causing ambiguity about which copy or method to use
A class has four parents
Two classes have the same name
Sign up free to see the answer and a step-by-step explanation.
None
Error
AA
BB
3
Error
BA
AB
BA
AB
False
Error
Some sound
Woof
Some sound Woof
Woof Some sound