Sheet Oop
Sheet Oop
a) A method
b) An object
c) A class
d) An operator
Answer: b
Explanation: An object represents an entity in the real world that can be distinctly identified. A class may
define an object.
x = change(1,2,3)
y = getattr(x, 'a')
setattr(x, 'a', y+1)
print(x.a)
a) 6
b) 7
c) Error
d) 0
Answer: b
Explanation: First, a=1+2+3=6. Then, after setattr() is invoked, x.a=6+1=7.
6. Suppose B is a subclass of A, to invoke the __init__ method in A from B, what is the line of code you
should write?
a) A.__init__(self)
b) B.__init__(self)
c) A.__init__(B)
d) B.__init__(A)
Answer: a
Explanation: To invoke the __init__ method in A from B, either of the following should be written:
A.__init__(self) or super().__init__(self).
class A():
pass
class B():
pass
class C(A,B):
pass
a) Multi-level inheritance
b) Multiple inheritance
c) Hierarchical inheritance
d) Single-level inheritance
Answer: b
Explanation: In multiple inheritance, two or more subclasses are derived from the superclass as shown
in the above piece of code.