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 set

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
If a parent class has a private variable and has no accessors for it, what would...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A) Suppose you have a class called base which has been inherited by a class called...

    A) Suppose you have a class called base which has been inherited by a class called derived.     ( both classes have public, protected and private members )     What can a client of derived access within the class base ?     What can the class derived access within the class base ? B) Suppose you have a class called more which has a private object of a class called simple. ( both classes have public, protected and private members...

  • Question 1 10 pts Inheritance is a capability of C++ to represent increased specialization that is...

    Question 1 10 pts Inheritance is a capability of C++ to represent increased specialization that is often found in real world relationships. True False Question 2 10 pts Inheritance between a child and parent object exhibits an 'relationship. Question 3 10 pts As you move down an inheritance relationship from parent to child, you typically move from a general to specific description. True False Question 4 10 pts The syntax for declaring DerivedClass to publicly inherit from BaseClass is given...

  • Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write...

    Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write a set method to make sure that if age > 125 years or less than 0 then it is set to 0 (default value) What does it indicate when declaring a class's instance variables with private access modifier? What is the role of a constructor? The data part of by an object's instance variables is known as? Do all methods have to always return...

  • Question 19 Given the following class: public class Swapper ( private int x; private String y...

    Question 19 Given the following class: public class Swapper ( private int x; private String y public int z; public Swapper( int a, String b, int c) ( x-a; y b; zC; public String swap() ( int temp -x; x-z z temp; return y: public String tostring() ( if (x<z) return y: else return" +x+z What would the following code output? Swapper r new Suapper( 5, "no", 10); System.out.printin( r. swap ) ): no no510 510 e 15 Question 20...

  • 1. Properties can contain both ______________ accessors. a. get and value b. get and set c....

    1. Properties can contain both ______________ accessors. a. get and value b. get and set c. return and set d. return and value 2. Identify the correct statement from the following: a. Properties cannot specify arbitrary parameters, although methods can. b. Read-only properties have both get and set accessors. c. Both properties and methods can be of type void. 3. Identify the correct explanation of an indexer. a. Indexers are differentiated by name, and a class can declare two indexers...

  • At face value this class seems ok ... but really it's not... select all that are...

    At face value this class seems ok ... but really it's not... select all that are true public class Student private Personal Info information; public Personal Info getInfo() return this.information; This is just a standard getter ... nothing wrong with that. Returning the Personalinfo reference can open this Student to direct manipulation of their data. A more robust public interface should be created to protect and control access to Personalinfo information. This is technically encapsulated properly, but could have very...

  • 2 points) Specifying private on a variable or method means it: is accessible in any other...

    2 points) Specifying private on a variable or method means it: is accessible in any other class. O is accessible in any other class within the same package. is accessible in derived classes and other classes in the same package. O is accessible in derived classes but not from other classes in the same package. is not accessible in derived classes but is accessible in other classes in the same pack- age. is not accessible in derived classes or from...

  • Hello! I know this has been answered before but I would love a new solution for it. This would be in C++ Create a class...

    Hello! I know this has been answered before but I would love a new solution for it. This would be in C++ Create a class named Building with one public pure virtual function computerEnergyConsumption() that returns a double value of the instance variable which stores the energy consumed by the building. Create the two classes SolarBuilding and WindMill that both publicly inherit from Building. SolarBuilding has an instance variable that stores the energy generated by the solar panels. WindMill has...

  • PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property...

    PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property 1 constructor that takes 3 arguments pass each argument to the appropriate property Task 2 In a new file import the Window class Instantiate the Window object Output the two public properties Task 3 Alter the Window class in Task 1 Add an accessor and mutator (the ability to access and change) to the private property Task 4 Create a class named Instrument Give...

  • Add a non-recursive inorder() method to class LinkedBinaryTree<E> to traverse binary tree. Test inorder() method. Implementation...

    Add a non-recursive inorder() method to class LinkedBinaryTree<E> to traverse binary tree. Test inorder() method. Implementation in Java #########LinkedBinary Tree class######### public class LinkedBinaryTree<E> extends AbstractBinaryTree<E> { //---------------- nested Node class ---------------- /** Nested static class for a binary tree node. */ protected static class Node<E> implements Position<E> { private E element; // an element stored at this node private Node<E> parent; // a reference to the parent node (if any) private Node<E> left; // a reference to the left...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT