Question

In: Computer Science

Which of the following options would be the worst violator of the principle of encapsulation? A)...

Which of the following options would be the worst violator of the principle of encapsulation?

A) Global variables

B) Local Variables

C) Public variables

D) Array variables

Can you also explain why the answer wouldn't be global variables, if A is not the correct answer?

Solutions

Expert Solution

Correct Answer: A

Explanation:

Encapsulation is a process through which we bind the data and code in a single unit.

This is the main feature of the Object-Oriented Programming concept. The private data members are hidden from the outside and can be accessed through methods only.

Because of encapsulation, a class has total control over the data stored in fields.

A global variable can be read or modified by any function or method or statement in the program. It is quickly difficult to know the global state in each instance. So, a global variable is the worst violator of the principle of encapsulation.

A local variable is a variable that is declared within a subroutine or block and it can be used inside that block only in which it is declared. This variable exists until the block is executed and after that, it is destroyed automatically. So, it doesn't violate the encapsulation.

In the same way, a public variable can be used in the same class and the inherited class only.

So, option A is the correct option.


Related Solutions

Which of the following sexually transmitted infections would you consider to be the “worst”: syphilis, gonorrhea,...
Which of the following sexually transmitted infections would you consider to be the “worst”: syphilis, gonorrhea, or chlamydia?  Why? Include clinical manifestations, complications, and prognosis in your answer. Would your choice be different for men vs women? Why?
Which of the following would be the worst enzymatic failure? Ornithin Transcarbamoylase    Argininosuccinase Carbamoyl Phosphate Synthetase...
Which of the following would be the worst enzymatic failure? Ornithin Transcarbamoylase    Argininosuccinase Carbamoyl Phosphate Synthetase I
Which of the following metals is the best reducing agent and which is the worst? a)...
Which of the following metals is the best reducing agent and which is the worst? a) Mn b) Al c) Ni d) Cr
Which of the following Cations is the best oxidizing agent and which is the worst? a)...
Which of the following Cations is the best oxidizing agent and which is the worst? a) Pb+2 b) Cr+3 c) Fe+2 d) Sn+2
Among the following acids, which is the best acid catalyst? Which is the worst?
  In acid-catalyzed addition of water to alkene, alcohol is the product. The conjugate base of the acid may compete with water for the newly formed carbocation and give a different product (other than alcohol). Among the following acids, which is the best acid catalyst? Which is the worst? Depend your answers.                HOAc     HCl      H2SO4       CF3COOH  
Which of the following options would you choose to have if therate of discount is...
Which of the following options would you choose to have if the rate of discount is 11 percent?A) $500 in one yearB) $850 in two yearsC) $920 in six yearsD) $1800 in ten years
Which species would be the worst choice as a Lewis acid? Explain why. A) NH3 B)...
Which species would be the worst choice as a Lewis acid? Explain why. A) NH3 B) LI+ C) BH3 D) HBr
which one is worst Alzheimer’s or dementia?
which one is worst Alzheimer’s or dementia?
32. Which of the following actions would be considered as self-interest threats? Select which two options...
32. Which of the following actions would be considered as self-interest threats? Select which two options are correct. Select one or more: An auditor acts as an advocate on behalf of an assurance client. A member of the assurance team is a director of the client. One client provides a high percentage of total audit fees. An auditor has potential employment with an assurance client. 35. Which of the following is the major purpose of performing analytical procedures? Select one:...
Please state the worst case run time for the following with an example of the worst...
Please state the worst case run time for the following with an example of the worst case and explain why! 1. Dijksta's Algorithm 2. Bellman-Ford Algorithm 3.DAG Algorithm 4. Prim's Algorithm 5. Kruskal's Algorithm 6. Baruvka's algorithm
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT