If a parent class has a private variable and has no accessors for it, what would
ID: 3907115 • Letter: I
Question
If a parent class has a private variable and has no accessors for it, what would be the best solution if a child class needed read only access to it? Best solution Allowing the child class to perform only the required (no additional optional) operations while preventing non-child classes access to it. O Declare the variable as private Declare the variable as protected O Declare the variable as public O Declare a public property for the variable O Declare a protected property for the variable O Declare a private property for the variable Declare a public property for the variable with a private set O Declare a protected property for the variable with a private set O Declare a private property for the variable with a private set Declare a public property for the variable with a protected set Declare a protected property for the variable with a protected set Declare a private property for the variable with a protected setExplanation / Answer
A) declare a protected property for the variable.
REASON: The protected keyword only allows the child classes to have access to the private variable that too read only.(if defined like an acessor)
B) Write an Account class with that redundant data and functionality, then implement it as the parent class for the three original account classes.
REASON: This is because the functionality and data is common to all, and if we define the functionality and inherit the class, then we need not provide the definition again and again!
C) Replace the ninety-nine duplicate checks with the "is" keyword to determine if the rock instance is a of type Geode.
REASON: the is keyword in some languages like "PYTHON" is used to check whether a given object is instance of some class. In java, the instanceof operator does the same work.
In case of any doubt, please let me know in the comments section. I'll get it resolved :):) Don't forget to give a THUMBS UP!! :):)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.