Compare and contrast the private visibility modifier to the protected visibility modifier. Why is the protected visibility modifier a better choice in an inheritance hierarchy?
What will be an ideal response?
The private modifier and the protected modifier both enforce the encapsulation of instance variables
and methods in a class. This means that unrelated classes are not able to directly access the variables and the methods. The
protected modifier, however, does allow for the instance variables and the methods to be accessed by subclasses of the
original class. This makes the protected modifier a better choice for use in an inheritance hierarchy, because it is often
useful for subclasses to have access to a superclass's instance variables and methods.
You might also like to view...
In SharePoint, a(n) ________ enables management of financial, asset, and cost accounting, production operations and materials, personnel, plants, and archived documents
A) enterprise search center B) SAP Workflow site C) community site D) team site
You can share worksheets or workbooks with others by ________
A) repeating the row and column titles on the pages of the worksheet B) inserting a page break C) using File Save As and renaming the file "share" D) printing paper copies, sending the file electronically, or posting the file to the web or a shared workspace