0% found this document useful (0 votes)
51 views3 pages

Python Inheritance and Output Quiz

The document contains multiple programming questions regarding class inheritance, method overriding, and object initialization in Python. It includes code snippets and multiple-choice options for each question, testing the reader's understanding of these concepts. The questions cover outputs of code execution, inheritance behavior, and function overloading.

Uploaded by

Jay Mishra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views3 pages

Python Inheritance and Output Quiz

The document contains multiple programming questions regarding class inheritance, method overriding, and object initialization in Python. It includes code snippets and multiple-choice options for each question, testing the reader's understanding of these concepts. The questions cover outputs of code execution, inheritance behavior, and function overloading.

Uploaded by

Jay Mishra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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.

You might also like