InfyTQ OOPS Concepts (Python) Quiz 1

Question 1

Time: 00:00:00
To create an object ______ is used.

class

class

constructor

constructor

User-defined functions

User-defined functions

In-built functions

In-built functions

Question 2

Time: 00:00:00
_____ represents an entity in the real world with its identity and behaviour.

An object

An object

An operator

An operator

A class

A class

A method

A method

Question 3

Time: 00:00:00
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

6

7

7

99

99

105

105

Question 4

Time: 00:00:00
class test():
def __repr__(self):
return 'This is called'
def __str__(self):
return 'No! This is called'
s=test()
print(s)

This is called

This is called

Nothing is printed

Nothing is printed

Error

Error

No! This is called

No! This is called

Question 5

Time: 00:00:00
 hasattr(obj, name) is used to?

access the attribute of the object

access the attribute of the object

delete an attribute

delete an attribute

check if an attribute exists or not

check if an attribute exists or not

set an attribute

set an attribute

Question 6

Time: 00:00:00
 The output to the following code will be:
class Engineer:
    'Base class for all students'
    def __init__(self, id_no, score):
       self.id_no = id_no
       self.score = score
    def display (self):
       print("Roll no : ", self.id_no,  ", Grade: ", self.score)
print(Engineer.__doc__)

None

None

Nothisg is printed

Nothisg is printed

Base class for all students

Base class for all students

Error

Error

Question 7

Time: 00:00:00
 predict the output
class Demo:
    def __init__(self):
        self.x = 0
class Derived_Demo(Demo):
    def __init__(self):
        self.y = 1
def main():
    b = Derived_Demo()
    print(b.x,b.y)
main()

 

0 1

0 1

1 0

1 0

0 0

0 0

Error

Error

Question 8

Time: 00:00:00
Determine the type if Inheritance:
class prep():
    pass
class insta():
    pass
class python(prep, insta):
    pass

Multi-level inheritance

Multi-level inheritance

Multiple inheritance

Multiple inheritance

Hierarchical inheritance

Hierarchical inheritance

Single-level inheritance

Single-level inheritance

Question 9

Time: 00:00:00
Which one is not true?

A non-private method in a superclass can be overridden

A non-private method in a superclass can be overridden

A derived class is a subset of a superclass

A derived class is a subset of a superclass

The value of a private variable in the superclass can be changed in the subclass

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

When invoking the constructor from a subclass, the constructor of the superclass is automatically invoked

Question 10

Time: 00:00:00
 What will be the output of the following code:
class D:
    def __init__(self,x):
        self.x = x
    def count(self,x):
        self.x = self.x+1
class C(D):
    def __init__(self, y=0):
        D.__init__(self, 5)
        self.y = y
    def count(self):
        self.y += 1     
def main():
    obj = C()
    obj.count()
    print(obj.x, obj.y)
main()

5 0

5 0

5 1

5 1

0 1

0 1

Error

Error

null
null