Q. 1

Which of the following is used to create an object ?

Options:

Explanation

Correct answer is : D

Constructor is used to create an object

Discuss It

Q. 2

What is the output of the following program ?

class MyClass:
    def __init__(self, x="Welcome"):
        self.x = x

    def display(self):
        print(self.x)

obj_ref = MyClass()
obj_ref.display()

Options:

Explanation

Correct answer is : B

The attribute "x" is set inside def __init__ while creating constructor here obj_ref = MyClass()
So when display() is called, it will print "Welcome"

Discuss It

Q. 3

What does Instantiation mean in OOPs ?

Options:

Explanation

Correct answer is : D

Creating an instance of a class is Instantiation

Discuss It

Q. 4

Which is a correct syntax to create an empty class ?

Options:

Explanation

Correct answer is : C

Empty class can be created by using class name and pass keyword

 

Discuss It

Q. 5

The methods inside a class with two underscores in the beginning and end are known as ?

Options:

Explanation

Correct answer is : None

The methods inside classed with double underscore ate the beginning and the end like __init__() are special methods having specific purposes

Discuss It

Q. 6

What is the output of the following code ?

class AttrTest:
    """This is AttrText class doc"""
    def __int__(self):
        """This is display doc """


obj = AttrTest()
print(AttrTest.__doc__)
print(obj.__doc__)

 

Options:

Explanation

Correct answer is : B

__doc__ for both the class name object and instance will print class document string 

Discuss It

Q. 7

Which special method overloads == operator ?

Options:

Explanation

Correct answer is : D

special method __eq__() overloads == operator

Discuss It

Q. 8

Which operator is overloaded by __lg__() method?

Options:

Explanation

Correct answer is : D

__lg__() is invalid

Discuss It

Q. 9

Which operator is overloaded by the __or__() method ?

Options:

Explanation

Correct answer is : None

| operator is overloaded by the __or__() 

Discuss It

Q. 10

What is the output of the following code ?

class A:
    def __init__(self):
        print("__init__ is called ")

    def __call__(self, *args, **kwargs):
        print("__call__ is called")

a = A()
a()


 

Options:

Explanation

Correct answer is : A

A() invokes __init__() method and a() invokes __call__() method 

Note : a() will raise error if __call__() is not definedinside the classs

Discuss It
Submit Your Answers

Interview Questions

on
Classes

Tutorial

on
Classes

Programs

on
Classes
Click any Link
to navigate to certain page easily
Write a line to us
Your Email
Title
Description