1.

Which among the following violates the principle of encapsulation almost always?(a) Local variables(b) Global variables(c) Public variables(d) Array variablesI got this question at a job interview.My query is from Encapsulation in division OOPs Concept & Features of Object Oriented Programming

Answer»

Correct answer is (b) Global variables

Explanation: Global variables almost ALWAYS violates the principles of encapsulation. Encapsulation says the data should be ACCESSED only by required set of elements. But global variable is accessible everywhere, also it is most prone to changes. It doesn’t HIDE the internal WORKING of PROGRAM.



Discussion

No Comment Found

Related InterviewSolutions