ExamVeda
Login
Home
21
The assignment of more than one function to a particular operator is . . . . . . . .
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
22
What is the difference between a class variable and an instance variable in Python?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
23
How can you access a class variable in Python?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
24
. . . . . . . . represents an entity in the real world with its identity and behaviour.
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
25
. . . . . . . . is used to create an object.
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
26
What are the methods which begin and end with two underscore characters called?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
27
What is setattr() used for?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
28
What is getattr() used for?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
29
What is the output of the following code:
class MyClass:
x = 5
obj = MyClass()
print(obj.x)
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
30
What is the output of the following code:
class Parent:
def show(self):
print('Parent method')
class Child(Parent):
pass
obj = Child()
obj.show()
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct answer is A: Parent method

Here's why:

We have a class called `Parent` that has a method named `show`. This method prints "Parent method".

Then, we create another class called `Child` that inherits from the `Parent` class. This means the `Child` class automatically gets all the methods and attributes of the `Parent` class.

Importantly, the `Child` class doesn't define its own `show` method. It inherits the `show` method directly from `Parent`.

We create an object of the `Child` class called `obj`.

When we call `obj.show()`, Python looks for a `show` method in the `Child` class. Since it doesn't find one there, it looks in the `Parent` class (because `Child` inherits from `Parent`).

It finds the `show` method in the `Parent` class and executes it. Therefore, it prints "Parent method".