This Quiz contains totally 10 Questions each carry 1 point for you.
1.Which of the following statements is true, for the below code?
PrintHello() is a function and a is a variable. None of them are objects.
Both printHello() and a refer to the same object.
PrintHello() and a refer to different objects.
Syntax error! Unable to assign function to a variable in Python.
Correct!
Wrong!
2. Is the following Python code correct?
class A:
def __init__(self,b):
self.b=b
def display(self):
print(self.b)
obj=A("Hello")
del obj
True
False
Correct!
Wrong!
3. Is the following Python code valid?
class B(object):
def first(self):
print("First method called")
def second():
print("Second method called")
ob = B()
B.first(ob)
No, as the object declaration isn’t right
No, as there is no__init__ method for initializing class members
Yes, this method of calling is named as unbounded method call
Yes, this method of calling is named as bounded method call
Correct!
Wrong!
4. What is the output of the following program?
x = 50
def func():
global x
x = 2
func()
print('Value of x is', x)
Error
Value of x is 50
Value of x is 2
None of the mentioned
Correct!
Wrong!
5. Which of the following statements is true?
In Python, depending upon operands same operator may behave differently.
The way operators behave can be changed in Python.
Special method __add()__ is called when + operator is used.
All of the above.
Correct!
Wrong!
6. Special methods need to be explicitly called during object creation.
True
False
Correct!
Wrong!
7. What is the output of the following code?
class Point:
def __init__(self, x = 0, y = 0):
self.x = x
self.y = y
def __sub__(self, other):
x = self.x + other.x
y = self.y + other.y
return Point(x,y)
p1 = Point(3, 4)
p2 = Point(1, 2)
result = p1-p2
print(result.x, result.y)
2 2
4 6
0 0
1 1
Correct!
Wrong!
8. This is the realized version of the class, where the class is manifested in the program.
Object
Blueprint
Attribute
Function
Correct!
Wrong!
9. In python, what is method inside class?
attribute
object
argument
function
Correct!
Wrong!
10. Which of the following is correct with respect to OOP concept in Python?
Objects are real world entities while classes are not real.
Classes are real world entities while objects are not real.
Both objects and classes are real world entities.
Both object and classes are not real.
Correct!
Wrong!
Share the quiz to show your results !
Subscribe to see your results
Ignore & go to results
Python-Objects-Quiz
You got %%score%% of %%total%% right
%%description%%
%%description%%
Loading...
