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

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 2

Time: 00:00:00
Predict the Output:

class doremon:

    def __init__(self, x, y, z):

        self.i = x + y + z

16

16

15

15

error

error

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

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

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

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

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

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

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

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

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

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

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

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

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

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

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

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

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

["0","40","60","80","100"]
["Need more practice!","Keep trying!","Not bad!","Good work!","Perfect!"]

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

0%

Comments