Explore topic-wise MCQs in Python.

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

1.

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» D. They can be accessed within a class
2.

The purpose of name mangling is to avoid unintentional access of private class members.

A. True
B. False
Answer» B. False
3.

Private members of a class cannot be accessed.

A. True
B. False
Answer» C.
4.

Which of these is a private data field?

A. __a
B. __b
C. __c__
D. __d__View Answer
Answer» C. __c__
5.

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» B. __repr__/__str__
6.

Which of the following is the most suitable definition for encapsulation?

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» C. Focuses on variables and passing of variables to functions
7.

Using encapsulation data security is ___________

A. Not ensured
B. Ensured to some extent
C. Purely ensured
D. Very low
Answer» C. Purely ensured
8.

Encapsulation is the way to add functions in a user defined structure.

A. True
B. False
Answer» C.
9.

Consider the code and select the wrong choice.

A. This maintains encapsulation
B. This code doesn’t maintain encapsulation
C. This code is vulnerable
D. This code gives errorView Answer
Answer» B. This code doesn’t maintain encapsulation
10.

Consider the following code and select the correct option.

A. This code is good to go
B. This code may result in undesirable conditions
C. This code will generate error
D. This code violates encapsulationView Answer
Answer» E.
11.

Which among the following can be a concept against encapsulation rules?

A. Using function pointers
B. Using char* string pointer to be passed to non-member function
C. Using object array
D. Using any kind of pointer/array address in passing to another function
Answer» E.
12.

Which among the following would destroy the encapsulation mechanism if it was allowed in programming?

A. Using access declaration for private members of base class
B. Using access declaration for public members of base class
C. Using access declaration for local variable of main() function
D. Using access declaration for global variables
Answer» B. Using access declaration for public members of base class
13.

Which among the following violates the principle of encapsulation almost always?

A. Local variables
B. Global variables
C. Public variables
D. Array variables
Answer» C. Public variables
14.

How can Encapsulation be achieved?

A. Using Access Specifiers
B. Using only private members
C. Using inheritance
D. Using Abstraction
Answer» B. Using only private members
15.

Which among the following should be encapsulated?

A. The data which is prone to change is near future
B. The data prone to change in long terms
C. The data which is intended to be changed
D. The data which belongs to some other class
Answer» B. The data prone to change in long terms
16.

Encapsulation helps in writing ___________ classes in java.

A. Mutable
B. Abstract
C. Wrapper
D. Immutable
Answer» E.
17.

Find which of the following uses encapsulation?a) void main(){ int a; void fun( int a=10; cout<<

A. void main(){ int a; void fun( int a=10; cout<<a); fun(); }
B. class student{ int a; public: int b;};
C. class student{int a; public: void disp(){ cout<<a;} };
D. struct topper{ char name[10]; public : int marks; }
Answer» D. struct topper{ char name[10]; public : int marks; }
18.

Which feature can be implemented using encapsulation?

A. Inheritance
B. Abstraction
C. Polymorphism
D. Overloading
Answer» C. Polymorphism
19.

While using encapsulation, which among the following is possible?

A. Code modification can be additional overhead
B. Data member’s data type can be changed without changing any other code
C. Data member’s type can’t be changed, or whole code have to be changed
D. Member functions can be used to change the data type of data members
Answer» C. Data member’s type can’t be changed, or whole code have to be changed
20.

If data members are private, what can we do to access them from the class object?

A. Create public member functions to access those data members
B. Create private member functions to access those data members
C. Create protected member functions to access those data members
D. Private data members can never be accessed from outside the class
Answer» B. Create private member functions to access those data members
21.

Which among the following best describes encapsulation?

A. It is a way of combining various data members into a single unit
B. It is a way of combining various member functions into a single unit
C. It is a way of combining various data members and member functions into a single unit which can operate on any data
D. It is a way of combining various data members and member functions that operate on those data members into a single unit
Answer» E.
22.

WHICH_AMONG_THE_FOLLOWING_VIOLATES_THE_PRINCIPLE_OF_ENCAPSULATION_ALMOST_ALWAYS??$

A. Local variables
B. Global variables
C. Public variables
D. Array variables
Answer» C. Public variables
23.

Which among the following can be a concept against encapsulation rules?$

A. Using function pointers
B. Using char* string pointer to be passed to non-member function
C. Using object array
D. Using any kind of pointer/array address in passing to another function
Answer» E.
24.

a$

A. The program has an error because b is private and display(self) is returning a private member
B. The program has an error because b is private and hence can’t be printed
C. The program runs fine and 1 is printed
Answer» D.
25.

Which_among_the_following_would_destroy_the_encapsulation_mechanism_if_it_was_allowed_in_programming?$

A. Using access declaration for private members of base class
B. Using access declaration for public members of base class
C. Using access declaration for local variable of main() function
D. Using access declaration for global variables
Answer» B. Using access declaration for public members of base class
26.

This maintains encapsulation

A. This code doesn’t maintain encapsulation
B. This code is vulnerable
C. This code gives error
Answer» C. This code gives error
27.

Private members of a class cannot be accessed. True or False?

A. True
B. False
Answer» C.
28.

This code is good to go

A. This code may result in undesirable conditions
B. This code will generate error
C. This code violates encapsulation
Answer» B. This code will generate error
29.

The program runs properly and prints 45

A. The program has an error because the value of members of a class can’t be changed from outside the class
B. The program runs properly and prints 1
C. The program has an error because the value of members outside a class can only be changed as self.a=45
Answer» D.
30.

__?

A. __b
B. __c__
C. __d__
Answer» C. __d__
31.

Which of these is not a fundamental features of OOP?

A. Encapsulation
B. Inheritance
C. Instantiation
D. Polymorphism
Answer» D. Polymorphism