Question
C++ Write a program to create three classes A , B , and C . Class B is derived from class A , and class
C++
Write a program to create three classes A, B, and C. Class B is derived from class A, and class C is derived from Class B. Use the member access specifier public when inheriting the classes. Each of these classes have a public method called print().
- The print() method of class A has a statement to print This is class A.
- The print() method of class B has a statement to print This is class B.
- The print() method of class C has a statement to print This is class C.
In your main program, create an object of class C, called objC and call the method print() of objC. It should print This is class C. What you just did is function overriding, where a method of a child class is hiding the methods of its parent classes.
Now, write statements to call methods print() of class B and C using objC.
Add another method in class A called localA(). The localA() has one statement to print, This is local method of A. Call localA() method using objC in your main program.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started