Explore topic-wise MCQs in Testing Subject.

This section includes 657 Mcqs, each offering curated multiple-choice questions to sharpen your Testing Subject knowledge and support exam preparation. Choose a topic below to get started.

1.

Which of the following best describes inheritance?

A. Ability of a class to derive members of another class as a part of its own definition
B. Means of bundling instance variables and methods in order to restrict access to certain class members
C. Focuses on variables and passing of variables to functions
D. Allows for implementation of elegant software that is well designed and easily modified
Answer» B. Means of bundling instance variables and methods in order to restrict access to certain class members
2.

What does print(Test.__name__) display (assuming Test is the name of the class) ?

A. ()
B. Exception is thrown
C. Test
D. __main__
Answer» D. __main__
3.

What is the output of the following piece of code? class stud: ‘Base class for all students’ def __init__(self, roll_no, grade): self.roll_no = roll_no self.grade = grade def display (self): print("Roll no : ", self.roll_no, ", Grade: ", self.grade) print(student.__doc__)

A. Exception is thrown
B. __main__
C. Nothing is displayed
D. Base class for all students
Answer» E.
4.

What is delattr(obj,name) used for?

A. To print deleted attribute
B. To delete an attribute
C. To check if an attribute is deleted or not
D. To set an attribute
Answer» C. To check if an attribute is deleted or not
5.

What is hasattr(obj,name) used for?

A. To access the attribute of the object
B. To delete an attribute
C. To check if an attribute exists or not
D. To set an attribute
Answer» D. To set an attribute
6.

What is the output of the following code? >>> class demo(): def __repr__(self): return '__repr__ built-in function called' def __str__(self): return '__str__ built-in function called' >>> s=demo() >>> print(s)

A. __str__ called
B. __repr__ called
C. Error
D. Nothing is printed
Answer» B. __repr__ called
7.

What is the output of the following code? >>> class demo(): def __repr__(self): return '__repr__ built-in function called' def __str__(self): return '__str__ built-in function called' >>> s=demo() >>> s

A. Error
B. Nothing is printed
C. __str__ called
D. __repr__ called
Answer» E.
8.

What are the methods which begin and end with two underscore characters called?

A. Special methods
B. In-built methods
C. User-defined methods
D. Additional methods
Answer» B. In-built methods
9.

Is the following piece of code valid? class B(object): def first(self): print("First method called") def second(): print("Second method called") ob = B() B.first(ob)

A. It isn’t as the object declaration isn’t right
B. It isn’t as there isn’t any __init__ method for initializing class members
C. Yes, this method of calling is called unbounded method call
D. Yes, this method of calling is called bounded method call
Answer» D. Yes, this method of calling is called bounded method call
10.

Which of the following is not a class method?

A. Non-static
B. Static
C. Bounded
D. Unbounded
Answer» B. Static
11.

The assignment of more than one function to a particular operator is _______

A. Operator over-assignment
B. Operator overriding
C. Operator overloading
D. Operator instance
Answer» D. Operator instance
12.

What is the output of the following code? class Demo: def __init__(self): pass def test(self): print(__name__) obj = Demo() obj.test()

A. Exception is thrown
B. __main__
C. Demo
D. test
Answer» C. Demo
13.

What is the output of the following code? class fruits: def __init__(self, price): self.price = price obj=fruits(50) obj.quantity=10 obj.bags=2 print(obj.quantity+len(obj.__dict__))

A. 12
B. 52
C. 13
D. 60
Answer» D. 60
14.

What is Instantiation in terms of OOP terminology?

A. Deleting an instance of class
B. Modifying an instance of class
C. Copying an instance of class
D. Creating an instance of class
Answer» E.
15.

What is the output of the following code? class test: def __init__(self,a): self.a=a def display(self): print(self.a) obj=test() obj.display()

A. Runs normally, doesn’t display anything
B. Displays 0, which is the automatic default value
C. Error as one argument is required while creating the object
D. Error as display function requires additional argument
Answer» D. Error as display function requires additional argument
16.

What is the output of the following code? class change: def __init__(self, x, y, z): self.a = x + y + z x = change(1,2,3) y = getattr(x, 'a') setattr(x, 'a', y+1) print(x.a)

A. 6
B. 7
C. Error
D. 0
Answer» C. Error
17.

What is getattr() used for?

A. To access the attribute of the object
B. To delete an attribute
C. To check if an attribute exists or not
D. To set an attribute
Answer» B. To delete an attribute
18.

What is setattr() used for?

A. To access the attribute of the object
B. To set an attribute
C. To check if an attribute exists or not
D. To delete an attribute
Answer» C. To check if an attribute exists or not
19.

What is the output of the following code? class test: def __init__(self,a="Hello World"): self.a=a def display(self): print(self.a) obj=test() obj.display()

A. The program has an error because constructor can’t have default arguments
B. Nothing is displayed
C. Hello World” is displayed
D. The program has an error display function doesn’t have parameters
Answer» D. The program has an error display function doesn’t have parameters
20.

____ is used to create an object.

A. class
B. constructor
C. User-defined functions
D. In-built functions
Answer» C. User-defined functions
21.

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

A. A method
B. An object
C. A class
D. An operator
Answer» C. A class
22.

Which function overloads the // operator?

A. __div__()
B. __ceildiv__()
C. __floordiv__()
D. __truediv__()
Answer» D. __truediv__()
23.

Which operator is overloaded by the __or__() function?

A. ||
B. |
C. //
D. /
Answer» C. //
24.

Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?

A. __add__(), __str__()
B. __str__(), __add__()
C. __sum__(), __str__()
D. __str__(), __sum__()
Answer» B. __str__(), __add__()
25.

Which function overloads the >> operator?

A. _more__()
B. __gt__()
C. __ge__()
D. none of the mentioned
Answer» E.
26.

Which operator is overloaded by __lg__()?

A. <
B. >
C. !=
D. none of the mentioned
Answer» E.
27.

Which function overloads the == operator?

A. __eq__()
B. __equ__()
C. __isequal__()
D. none of the mentioned
Answer» B. __equ__()
28.

Which operator is overloaded by __invert__()?

A. !
B. ~
C. ^
D.
Answer» C. ^
29.

Which function overloads the + operator?

A. __add__()
B. __plus__()
C. __sum__()
D. none of the mentioned
Answer» B. __plus__()
30.

Which function is called when the following code is executed? f = foo() format(f)

A. format()
B. __format__()
C. str()
D. __str__()
Answer» E.
31.

What happens if no arguments are passed to the seek function?

A. file position is set to the start of file
B. file position is set to the end of file
C. file position remains unchanged
D. error
Answer» E.
32.

How do you change the file position to an offset value from the start?

A. fp.seek(offset, 0)
B. fp.seek(offset, 1)
C. fp.seek(offset, 2)
D. none of the mentioned
Answer» B. fp.seek(offset, 1)
33.

How do you delete a file?

A. del(fp)
B. fp.delete()
C. os.remove(‘file’)
D. os.delete(‘file’)
Answer» D. os.delete(‘file’)
34.

How do you rename a file?

A. fp.name = ‘new_name.txt’
B. os.rename(existing_name, new_name)
C. os.rename(fp, new_name)
D. os.set_name(existing_name, new_name)
Answer» C. os.rename(fp, new_name)
35.

How do you get the current position within the file?

A. fp.seek()
B. fp.tell()
C. fp.loc
D. fp.pos
Answer» C. fp.loc
36.

How do you close a file object (fp)?

A. close(fp)
B. fclose(fp)
C. fp.close()
D. fp.__close__()
Answer» D. fp.__close__()
37.

Which of the following is not a valid attribute of a file object (fp)?

A. fp.name
B. fp.closed
C. fp.mode
D. fp.size
Answer» E.
38.

How do you get the name of a file from a file object (fp)?

A. fp.name
B. fp.file(name)
C. self.__name__(fp)
D. fp.__name__()
Answer» B. fp.file(name)
39.

What is the difference between r+ and w+ modes?

A. no difference
B. in r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for w+
C. in w+ the pointer is initially placed at the beginning of the file and the pointer is at the end for r+
D. depends on the operating system
Answer» C. in w+ the pointer is initially placed at the beginning of the file and the pointer is at the end for r+
40.

Which of the following is not a valid mode to open a file?

A. ab
B. rw
C. r+
D. w+
Answer» C. r+
41.

Which of the following is modes of both writing and reading in binary format in file.?

A. wb+
B. w
C. wb
D. w+
Answer» B. w
42.

Is it possible to create a text file in python?

A. Yes
B. No
C. Machine dependent
D. All of the mentioned
Answer» B. No
43.

Which function is used to close a file in python?

A. Close()
B. Stop()
C. End()
D. Closefile()
Answer» B. Stop()
44.

Which function is used to write a list of string in a file

A. writeline()
B. writelines()
C. writestatement()
D. writefullline()
Answer» B. writelines()
45.

Which function is used to write all the characters?

A. write()
B. writecharacters()
C. writeall()
D. writechar()
Answer» B. writecharacters()
46.

Which function is used to read single line from file?

A. Readline()
B. Readlines()
C. Readstatement()
D. Readfullline()
Answer» C. Readstatement()
47.

Which function is used to read all the characters?

A. Read()
B. Readcharacters()
C. Readall()
D. Readchar()
Answer» B. Readcharacters()
48.

. What is the use of “a” in file handling?

A. Read
B. Write
C. Append
D. None of the the mentioned
Answer» D. None of the the mentioned
49.

What is the use of “w” in file handling?

A. Read
B. Write
C. Append
D. None of the the mentioned
Answer» C. Append
50.

In file handling, what does this terms means “r, a”?

A. read, append
B. append, read
C. all of the mentioned
D. none of the the mentioned
Answer» B. append, read