class A{ protected: int x, y; public: int z; }; class B: private A{ private: int a, b, c; public:

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 1TF: Mark the following statements as true or false. a. In single inheritance, a base class can create...
icon
Related questions
Question

Read the question carefully Please answer correctly.

ii.
Consider the following inheritance hierarchy:
class A{
protected:
int x, y;
public:
int z;
};
class B: private A{
private:
int a, b, c;
public:
void set(int x, int y, int z, int a, int b, int c);
};
Int main(){
Aobja;
B objb;
}
Answer Correctly :
a) How many data members does B have? Write their names.
b) How many of B's data members are visible in B? Write down their names.
c) Which members of B are accessible in main()? How will they be accessed?
d) If the protected Access specifier in A is changed to public, then how many members of B will be
accessed in main() and how?
e) Define the function set() without changing its signature as given above.
f) Write a default constructor for the class B that does not have an empty parameter list.
g) If the data members of A become private, then how they be initialized?
h) Add a static data member in class B. Can we use this pointer with static members? If yes how?
Transcribed Image Text:ii. Consider the following inheritance hierarchy: class A{ protected: int x, y; public: int z; }; class B: private A{ private: int a, b, c; public: void set(int x, int y, int z, int a, int b, int c); }; Int main(){ Aobja; B objb; } Answer Correctly : a) How many data members does B have? Write their names. b) How many of B's data members are visible in B? Write down their names. c) Which members of B are accessible in main()? How will they be accessed? d) If the protected Access specifier in A is changed to public, then how many members of B will be accessed in main() and how? e) Define the function set() without changing its signature as given above. f) Write a default constructor for the class B that does not have an empty parameter list. g) If the data members of A become private, then how they be initialized? h) Add a static data member in class B. Can we use this pointer with static members? If yes how?
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Form
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage