Python Programming (2180711) MCQs

MCQs of Classes and Object-Oriented Programming

Showing 41 to 45 out of 45 Questions
41.
Methods of a class that provide access to private members of the class are called as ______ and ______
(a) getters/setters
(b) __repr__/__str__
(c) user-defined functions/in-built functions
(d) __init__/__del__
Answer:

Option (a)

42.
Which of these is a private data field?
def Demo:
def __init__(self):
    __a = 1
    self.__b = 1
    self.__c__ = 1
    __d__= 1
(a) __a
(b) __b
(c) __c__
(d) __d__
Answer:

Option (b)

43.
Private members of a class cannot be accessed.
(a) TRUE
(b) FALSE
Answer:

Option (b)

44.
The purpose of name mangling is to avoid unintentional access of private class members.
(a) TRUE
(b) FALSE
Answer:

Option (a)

45.
Which of the following is false about protected class members?
(a) They begin with one underscore
(b) They can be accessed by subclasses
(c) They can be accessed by name mangling method
(d) They can be accessed within a class
Answer:

Option (c)

Showing 41 to 45 out of 45 Questions