Question 31
MediumWhat is multilevel inheritance?
- A.
A class inheriting from itself
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
What is multilevel inheritance?
A class inheriting from itself
A class inheriting from several classes at once
Several classes inheriting from one class
A chain such as A → B → C, where C inherits from B and B from A
Sign up free to see the answer and a step-by-step explanation.
Are constructors inherited in Java?
Only in abstract classes
Yes, always
Only private constructors
No, but a subclass constructor calls a superclass constructor (explicitly or implicitly)
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class A: pass
class B(A): pass
class C(A): pass
class D(B, C): pass
print(" ".join(k.__name__ for k in D.__mro__[:-1]))
D A B C
D C B A
Sign up free to see the answer and a step-by-step explanation.
Which members of a base class are NOT accessible in a derived class in C++?
Private members
Protected members
Static public members
Public members
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"; }
~A() { cout << "a"; }
};
class B : public A {
public:
B() { cout << "B"; }
~B() { cout << "b"; }
};
int main() {
B obj;
}
BAba
ABab
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: int x = 1; };
class B : public A { public: int x = 2; };
int main() {
B b;
cout << b.x << b.A::x;
}
12
11
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class A:
def hello(self):
return "A"
class B(A):
def hello(self):
return "B" + super().hello()
class C(B):
def hello(self):
return "C" + super().hello()
print(C().hello())
CB
ABC
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class A:
def who(self): return "A"
class B(A):
def who(self): return "B"
class C(A):
def who(self): return "C"
class D(B, C):
pass
print(D().who(), [k.__name__ for k in D.__mro__][1:3])
C ['C', 'B']
A ['A', 'B']
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class Base:
def __init__(self):
self.x = 1
class Child(Base):
def __init__(self):
self.y = 2
c = Child()
print(hasattr(c, "x"), hasattr(c, "y"))
True True
False True
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 Base {
public:
void show() { cout << "Base "; }
};
class Derived : public Base {
public:
void show() { cout << "Derived "; }
};
int main() {
Derived d;
Base *p = &d;
p->show();
d.show();
}
Derived Base
Base Derived
Sign up free to see the answer and a step-by-step explanation.
D B C A
D B A C
ABba
BAab
22
21
C
CBA
B ['A', 'C']
B ['B', 'C']
True False
False False
Base Base
Derived Derived