On some occasions, you might want to access parent class data from a child class. Declaring the parent class field as public would violate the principle of information hiding, but declaring it private would make it inaccessible. How can the proper level of security be achieved?

What will be an ideal response?

If you want a derived class property or method to be able to access a parent's field, then it cannot be private. However, if you don't want other, nonchild classes to access the field, then it cannot be public. The solution is to create the field using the modifier protected, which provides you with an intermediate level of security between public and private access. A protected data field or method can be used within its own class or in any classes extended from that class, but it cannot be used by "outside" classes. In other words, protected members can be used "within the family"-by a class and its descendants.

Computer Science & Information Technology

You might also like to view...

A firewall consists of ________

A) software only B) hardware only C) a combination of hardware and software D) a brick wall in front of the PC

Computer Science & Information Technology

Which one of the following backup types does not alter the status of the archive bit on a file?

A. Full backup B. Incremental backup C. Partial backup D. Differential backup

Computer Science & Information Technology