Session 1
1.What will be the output of the following Python code?
class Test: def __init__(self): self.x = 0 class Test1(Test): def __init__(self): self.y = 1 def main(): b = Test1() print(b.x,b.y) main()
c. ) Error because class B inherits A but variable x isn’t inherited
2.Which of the following statements isn’t true?
c.) The value of a private variable in the superclass can be changed in the subclass
3.)Output:
class A:
def __init__(self):
self._x = 5
class B(A):
def display(self):
print(self._x)
def main():
obj = B()
obj.display()
main()
Ans: C). 5
4.)What does built-in function type do in context of classes?
Ans: C)Determines class description of any value
5. What is the use of duck typing?
Ans: C) Less restriction on the type values that can be passed to a given method
6. What type of inheritance is illustrated in the following Python code?
class A():
pass
class B():
pass
class C(A,B):
pass
Ans: B) Multiple Inheritance
7.What will be the output of the following Python code?
class Demo:
def __init__(self):
pass
def test(self):
print(__name__)
obj = Demo()
obj.test()
Ans:B.__main__
8.Which of the following statements is true?
a)The new() method automatically invokes the init method
b)The init method is dened in the object class
c)The __eq(other) method is dened in the object class
d)The repr() method is dened in the object class
Ans : c)The __eq(other) method is dened in the object class
9.)What will be the output of the following Python 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()
Ans:A.) test of B called test of C called test of A called
10.)What will be the output of the following Python code?
class A:
def __str__(self):
return '1'
class B(A):
def __init__(self):
super().__init__()
class C(B):
def __init__(self):
super().__init__()
def main():
obj1 = B()
obj2 = A()
obj3 = C()
print(obj1, obj2,obj3)
main()
Ans : A) 1 1 1
11.)Which of the following is not a type of inheritance?
A) Double-level
B)Multi-level
C)Single-level
D)Multiple
Ans: A) Double-level
12.)What type of inheritance is illustrated in the following Python code?
class A():
pass
class B():
pass
class C(B):
pass
Ans: A) Multi-level Inheritance
13.)All sub classes are a sub type in object-oriented programming.
A)True
B)False
Ans: B)False
14.)What does single-level inheritance mean?
A)A subclass derives from a class which in turn derives from another class
B) A single superclass inherits from multiple subclasses
C)A single subclass derives from a single superclass
D)Multiple base classes inherit a single derived class
Ans: C)A single subclass derives from a single superclass
15.)Which of the following statements is true?
a)The new() method automatically invokes the init method
b)The init method is dened in the object class
c)The __eq(other) method is dened in the object class
d)The repr() method is dened in the object class
Ans : c)The __eq(other) method is dened in the object class
16)What will be the output of the following Python code?
class A:
def __init__(self, x= 11):
self.x = x
class der(A):
def __init__(self,y = 22):
super().__init__()
self.y = y
def main():
obj = der()
print(obj.x, obj.y)
main()
Post a Comment