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; } questions: 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
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
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; }
questions:
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?
Trending now
This is a popular solution!
Step by step
Solved in 2 steps