Question 1
class
constructor
User-defined functions
In-built functions
Good Job!
Oops!
The values assigned by the constructor to the class members are used to create the object.
Please login to submit your explanation
You can check your performance of this question after Login/Signup
Start
Question 2
16
15
error
First, i=4+5+6=15. Then, after setattr() is invoked, x.i=15+1=16.
Question 3
class pizza: def __init__(self, money): self.money = money obj=pizza(99) obj.amount=4 obj.total=2 print(obj.amount+len(obj.__dict__)) The output of the following code will be:
6
7
99
105
In the above code, obj.quantity has been initialised to 4. There are a total of three items in the dictionary, price, quantity and bags. Hence, len(obj.__dict__) is 3.
Question 4
class test(): def __repr__(self): return 'This is called' def __str__(self): return 'No! This is called' s=test() print(s)
This is called
Nothing is printed
Error
No! This is called
__str__ is used for producing a string representation of an object’s value that Python can evaluate. Execute in python shell to verify.
Question 5
access the attribute of the object
delete an attribute
check if an attribute exists or not
set an attribute
: hasattr(obj, name) checks if an attribute exists or not and returns True or False.
Question 6
None
Nothisg is printed
Base class for all students
___doc__ built-in class attribute is used to print the class documentation string or none, if undefined.
Question 7
0 1
1 0
0 0
Since the invoking method, Demo.__init__(self), isn’t present in the derived class, variable x can’t be inherited.
Question 8
Multi-level inheritance
Multiple inheritance
Hierarchical inheritance
Single-level inheritance
In multiple inheritance, two or more subclasses are derived from the superclass as shown in the above piece of code.
Question 9
A non-private method in a superclass can be overridden
A derived class is a subset of a superclass
The value of a private variable in the superclass can be changed in the subclass
When invoking the constructor from a subclass, the constructor of the superclass is automatically invoked
If the value of a private variable in a superclass is changed in the subclass, the change isn’t reflected.
Question 10
5 0
5 1
Initially x=5 and y=0. When obj.count() is called, y=1.
Please login to report
Login/Signup
Personalized Analytics only Availble for Logged in users
Analytics below shows your performance in various Mocks on PrepInsta
Your average Analytics for this Quiz
Rank
-
Percentile
0%
Completed
0/0
Accuracy
March 31, 2021
Login/Signup to comment
Login/Signup to comment