If a parent class has a private variable and has no accessors for it, what would
ID: 3907059 • 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
Please Note: As per Chegg Answering Guidelines, I have answered the first question. Please Post Separate for Separate Questions.
Q1)
If a parent class has a private variable and has no assessors for it, what would be the best solution if a child class needed only read access to it?
Answer)
Declare a private property for the variable with a protected set
This will mean. That in the superclass we will declare the variable as private but we will have an accessors for it protected state such that the child class can have read only access to the variable.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.