Join Our WhatsApp Group Join Subscribe Now!

Object Oriented Programming Using C++ (313304) Practical No.17: Write programs for- Pointer to derived class in single inheritance Answer

Object Oriented Programming Using C++ (313304)

 Object Oriented Programming Using C++ (313304) Practical No.17: Write programs for Pointer to derive class in single inheritance Answer

The key feature of class inheritance is that a pointer to a derived class is type-compatible with a pointer to its base class.

Object Oriented Programming Using C++ (313304)

Exercise:

1. State output of the following code:

#include<iostream.h>
class base {
public:
void show()
cout << "base\n";
} ;
class derived: public base
public:
void show() {
cout << "derived\n";
} ;
void main()
{
base bl;
bl.show();
derived dl;
dl.show();
base *pb = &bl;
pb->show();
pb = &dl;
pb->show();
}

Answer:

Base

derived 

Base

 base

2. A pointer to the base class can hold the address of A) only base class object B) only derived class object C) base class object as well as derived class object D) None of the above

Answer:

C) base class object as well as derived class object
3. A pointer can be initialized with
a) Null b) zero c)Address of an object of the same type d) All of them

Answer:

d) All of them
4. Which variable stores the memory address of another variable?
A) Reference B) Pointer C) Array D) None of the above

Answer:

B) Pointer

Practical Related Questions

1. Write a C++ program declare a class "polygon" having data members width and height. Derive classes "rectangle" and "triangle" from "polygon" having area() as a member function. Calculate area of triangle and rectangle using pointer to derived class object.

Answer:



2. Write a program that shows the use of Pointer to derive class in multilevel inheritance.

Answer:


3. Complete the following table:

oop

Conclusion

We successfully completed Object Oriented Programming Using C++ (313304) Practical No.17 in which we Write programs for Pointer to derive classes in single inheritance.

About the Author

Hi everyone, I'm Suraj Diware, and I'm passionate about helping students succeed in MSBTE programs. This blog is dedicated to providing clear and concise explanations of MSBTE curriculum topics, along with practical tips and resources to sup…

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.