Python OOPs MCQs

This section focuses on the "oops" in Python. These Multiple Choice Questions (mcq) should be practiced to improve the Python skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. Which of the following is correct with respect to OOP concept in Python?

A. Objects are real world entities while classes are not real.
B. Classes are real world entities while objects are not real.
C. Both objects and classes are real world entities.
D. Both object and classes are not real.

View Answer


2. How many objects and reference variables are there for the given Python code?

class A:
	print("Inside class")
A()
A()
obj=A()

A. 2 and 1
B. 3 and 3
C. 3 and 1
D. 3 and 2

View Answer


3. Which of the following is False with respect Python code?

class Student:
def __init__(self,id,age):
self.id=id
self.age=age
std=Student(1,20)

A. "std" is the reference variable for object Student(1,20)
B. id and age are called the parameters.
C. Every class must have a constructor.
D. None of the above

View Answer


4. What will be the output of below Python code?

class Student:
def __init__(self,name,id):
self.name=name
self.id=id
print(self.id)
std=Student("Simon",1)
std.id=2
print(std.id)

A. 1
    1
B. 1
    2
C. 2
    1
D. 2
    2

View Answer


5. What will be the output of below Python code?

class A():
def __init__(self,count=100):
self.count=count

obj1=A()
obj2=A(102)
print(obj1.count)
print(obj2.count)

A. 100
    100
B. 100
    102
C. 102
    102
D. Error

View Answer


6. Which of the following is correct?

class A:
    def __init__(self,name):
        self.name=name
a1=A("john")
a2=A("john")

A. id(a1) and id(a2) will have same value.
B. id(a1) and id(a2) will have different values.
C. Two objects with same value of attribute cannot be created.
D. None of the above

View Answer


7. Which of the following is correct?

class A:
def __init__(self):
self.count=5
self.count=count+1
a=A()
print(a.count)

A. 5
B. 6
C. 0
D. Error

View Answer


8. Which of the following is correct?

class Book:
	def __init__(self,author):
		self.author=author
book1=Book("V.M.Shah")
book2=book1

A. Both book1 and book2 will have reference to two different objects of class Book.
B. id(book1) and id(book2) will have same value.
C. It will throw error as multiple references to same object is not possible.
D. None of the above

View Answer


9. In python, what is method inside class?

A. attribute
B. object
C. argument
D. function

View Answer


10. What will be the output of below Python code?

class A:
def __init__(self,num):
num=3
self.num=num
def change(self):
self.num=7
a=A(5)
print(a.num)
a.change()
print(a.num)

A. 5
     7
B. 5
     5
C. 3
     3
D. 3
     7

View Answer






Discussion



* You must be logged in to add comment.

LALITHA SAGI .
9/10