Question

How do the public, private and protected keywords affect inheritance of the use of data and...

How do the public, private and protected keywords affect inheritance of the use of data and function members of a parent class by a child class.

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

Affect of Public,Private and Protected to Inheritance:

Public- Public members (generally methods declared in a class) are accessible from outside the class. The object of the same class is required to invoke a public method.

Private-  Private members of a class are denied access from the environment outside the class. They can be handled only from within the class.

Protected- Protected members of a class are accessible from within the class and are also available to its sub-classes. No other environment is permitted access to it. This enables specific resources of the parent class to be inherited by the child class.

Add a comment
Know the answer?
Add Answer to:
How do the public, private and protected keywords affect inheritance of the use of data and...
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
  • 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...

  • Discuss the importance of the protected access modifier. Provide examples of when to make parent class...

    Discuss the importance of the protected access modifier. Provide examples of when to make parent class data fields private versus protected and how a derived class can access the constructor of its parent class. Consider how the parent/child relationship is enforced with the keyword and the importance of inheritance in application development. Also, discuss how multiple inheritance is commonly used in object-oriented programming languages.

  • 1.Which of the following modifiers allow for inheritance? Make two selections.    public     protected    ...

    1.Which of the following modifiers allow for inheritance? Make two selections.    public     protected     portable     private 2. Which one of the following is a class header indicating that we are defining a class named Amphibian, which is derived from the Animal class?    Amphibian extends Animal     Animal->Amphibian     Amphibian : Animal     Animal(Amphibian) 3. You have a parent class called Account, and a derived class called CheckingAccount. How would you go about initializing an instance of...

  • If a parent class has a private variable and has no accessors for it, what would...

    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...

  • Adapt the provided program to recreate the following tree: import java.util.ArrayList; import java.util.List; public class TreeNode<T>{ public T data = null; private List<TreeNode> childr...

    Adapt the provided program to recreate the following tree: import java.util.ArrayList; import java.util.List; public class TreeNode<T>{ public T data = null; private List<TreeNode> children = new ArrayList<>(); private TreeNode parent = null; public TreeNode() { }    public TreeNode(T data) { this.data = data; } public TreeNode<T> addChild(TreeNode child) { child.setParent(this); this.children.add(child); return child; } public TreeNode<T> addChild(T data) { TreeNode<T> newChild = new TreeNode<>(data); newChild.setParent(this); children.add(newChild); return newChild; } public void addChildren(List<TreeNode> children) { for(TreeNode t : children) { t.setParent(this);...

  • What are constructors? Explain why they are needed in an object-oriented programming language. If inheritance takes...

    What are constructors? Explain why they are needed in an object-oriented programming language. If inheritance takes place, what is the order in which the parent and child constructors are called? Can a constructor be overloaded? Can a constructor be overridden? Explain when a destructor should be declared as virtual in C+? Explain the use of the access specifiers public, protected and private in C++. Which is the default specifier?

  • What is output? public abstract class People { protected string name; protected int age; public abstract...

    What is output? public abstract class People { protected string name; protected int age; public abstract void PrintInfo(); public void PrintInformation() { System.out.println("In Base Class People"); public class Teacher extends People { private int experience; public void PrintInfo() { System.out.println("In Child Class Teacher"); public class Principal extends Teacher { public void PrintInformation() { System.out.println("In Child Class Principal"); public static void main(String args[]) { Principal tim; tim = new Principal(); tim.PrintInfo(); In Base Class People Error: Compiler error In Child Class...

  • Create class definitions using the following: Classes: Circle, Cube, Shape, Sphere, Square, ThreeDimensionalShape, TwoDimensionalShape Functions: Draw,...

    Create class definitions using the following: Classes: Circle, Cube, Shape, Sphere, Square, ThreeDimensionalShape, TwoDimensionalShape Functions: Draw, GetArea, GetDimensions, GetHeight, GetLength, GetSurfaceArea, GetVolume Members: height, length, width – all of type double Don’t actually write function implementations, just define the classes as you would in a header file. Use inheritance as appropriate. Use keywords such as “const” and “virtual” as appropriate. Make functions and members public, private, or protected as appropriate. Don’t forget constructors and destructors. Some classes may be abstract,...

  • For Questions 1-3: consider the following code: public class A { private int number; protected String...

    For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() {    super();    System.out.println(“B() called”);...

  • For Questions 1-3: consider the following code: public class A { private int number; protected String...

    For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() {   super();   System.out.println(“B() called”); } public...

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