Some programmers prefer not to use protected access, because they believe it breaks the encapsulation of the base class. Discuss the relative merits of using protected access vs. using private access in base classes.
What will be an ideal response?
private instance variables are hidden in the derived class and are accessible only
through the public or protected properties and methods of the base class. Using
protected access enables the derived class to manipulate the protected members
without using the properties and methods of the base class. If the base class instancae
variables are private, the properties of the base class must be used to access the data.
This may result in a decrease in performance due to the extra accessor and method
calls. Declaring private instance variables in a base class helps you test, debug and
correctly modify systems. If a derived class could access its base class’s private instance
variables, classes that inherit from that base class could access the instance variables
as well. This would propagate access to what should be private instance
variables, and the benefits of information hiding would be lost.
You might also like to view...
All healthcare entities must now demonstrate meaningful use to avoid financial penalties to receive grants from the HITECH Act
Indicate whether the statement is true or false
In programming, combining two strings a and b into a single string ab is called ____ the strings.
A. adding B. concatenating C. merging D. joining