1. What is the output of the following piece of code?
class Test:
def __init__(self):
self.x = 0
class Derived_Test(Test):
def __init__(self):
self.y = 1
def main():
b = Derived_Test()
print(b.x,b.y)
main()
a) 0 1
b) 0 0
c) Error because class B inherits A but variable x isn’t inherited
d) Error because when object is created, argument must be passed like Derived_Test(1)
2.
What is the output of the following piece of code?
class A():
def disp(self):
print("A disp()")
class B(A):
pass
obj = B()
[Link]()
a) Invalid syntax for inheritance
b) Error because when object is created, argument must be passed
c) Nothing is printed
d) A disp()
3.
What is the output of the following piece of code?
class A:
def one(self):
return [Link]()
def two(self):
return 'A'
class B(A):
def two(self):
return 'B'
obj1=A()
obj2=B()
print([Link](),[Link]())
a) A A
b) A B
c) B B
d) An exception is thrown
4.
Which Of The Following Statements Are Correct About The Given
Code Snippet?
class A:
def __init__(self, i = 0):
self.i = i
class B(A):
def __init__(self, j = 0):
self.j = j
def main():
b = B()
print(b.i)
print(b.j)
main()
A. Class B inherits A, but the data field “i” in A is not inherited.
B. Class B inherits A, thus automatically inherits all data fields in A.
C. When you create an object of B, you have to pass an argument such as B(5).
D. The data field “j” cannot be accessed by object b.
5.
class Sales:
def __init__(self, id):
[Link] = id
id = 100
val = Sales(123)
print ([Link])
A. SyntaxError, this program will not run
B. 100
C. 123
D. None of the above
6. Write a program to overloading a function of two product multiplication by a three
product multiplication.