Take as many assements as you can to improve your validate your skill rating
Total Questions: 20
1. What does single-level inheritance mean?
Correct Answer is : A single subclass derives from a single superclass
2. What is the output of the following piece of code?
class A:
def __init__(self):
self.__i = 1
self.j = 5
def display(self):
print(self.__i, self.j)
class B(A):
def __init__(self):
super().__init__()
self.__i = 2
self.j = 7
c = B()
c.display()
Correct Answer is : 45298
3. Which of the following statements isn’t true?
Correct Answer is : The value of a private variable in the superclass can be changed in the subclass
4. What is the output of the following piece of code?
class A:
def __init__(self,x):
self.x = x
def count(self,x):
self.x = self.x+1
class B(A):
def __init__(self, y=0):
A.__init__(self, 3)
self.y = y
def count(self):
self.y += 1
def main():
obj = B()
obj.count()
print(obj.x, obj.y)
main()
Correct Answer is : 45352
5. What is the output of the following piece of code when executed in the Python shell?
>>> class A:
pass
>>> class B(A):
pass
>>> obj=B()
>>> isinstance(obj,A)
Correct Answer is : TRUE
6. Which of the following statements is true?
Correct Answer is : The __eq(other) method is defined in the object class
7. Method issubclass() checks if a class is a subclass of another class. True or False?
Correct Answer is : TRUE
8. What is the output of the following piece of code?
class A:
def __init__(self):
self.__x = 1
class B(A):
def display(self):
print(self.__x)
def main():
obj = B()
obj.display()
main()
Correct Answer is : Error, private class member can’t be accessed in a subclass
9. What is the output of the following piece of code?
class A:
def __init__(self):
self._x = 5
class B(A):
def display(self):
print(self._x)
def main():
obj = B()
obj.display()
main()
Correct Answer is : 5
10. What is the output of the following piece of code?
class A:
def __init__(self,x=3):
self._x = x
class B(A):
def __init__(self):
super().__init__(5)
def display(self):
print(self._x)
def main():
obj = B()
obj.display()
main()
Correct Answer is : 5
11. What is the output of the following piece of code?
class A:
def test1(self):
print(" test of A called ")
class B(A):
def test(self):
print(" test of B called ")
class C(A):
def test(self):
print(" test of C called ")
class D(B,C):
def test2(self):
print(" test of D called ")
obj=D()
obj.test()
Correct Answer is : test of B called
12. What is the output of the following piece of code?
class A:
def test(self):
print("test of A called")
class B(A):
def test(self):
print("test of B called")
super().test()
class C(A):
def test(self):
print("test of C called")
super().test()
class D(B,C):
def test2(self):
print("test of D called")
obj=D()
obj.test()
Correct Answer is : test of B called
13. What is the output of the following?
k = [print(i) for i in my_string if i not in "aeiou"]
Correct Answer is : prints all characters of my_string that aren’t vowels
14. What is the output of print(k) in the following?
k = [print(i) for i in my_string if i not in "aeiou"]
print(k)
Correct Answer is : a list of Nones
15. What is the output of the following?
my_string = "hello world"
k = [(i.upper(), len(i)) for i in my_string]
print(k)