Encapsulation
1.

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

2.

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

3.

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

4.

Which feature can be implemented using encapsulation ?

A.  

Inheritance

B.  

Abstraction

C.  

Polymorphism

D.  

Overloading

5.

Find which of the following uses encapsulation ?

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; }

6.

Encapsulation helps in writing ___________ classes in java.

A.  

Mutable

B.  

Abstract

C.  

Wrapper

D.  

Immutable

7.

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

8.

How can Encapsulation be achieved ?

A.  

Using Access Specifiers

B.  

Using only private members

C.  

Using inheritance

D.  

Using Abstraction

9.

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

A.  

Local variables

B.  

Global variables

C.  

Public variables

D.  

Array variables

10.

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