If class D is derived from a base class B



If class D is derived from a base class B..

Answer / Somendra Pandey

When class D is derived from a base class B, it inherits all the members (functions and variables) of the base class B. Additionally, you can add new members to the derived class D.nnFor example:nn```cppn#include <iostream>nnclass Base {npublic:n void sayHello() const {n std::cout << "Hello, I am a base class!";n }n};nnclass Derived : public Base {npublic:n void addSomething() {n std::cout << " and I am adding something!";n }n};nnint main() {n Derived d;n d.sayHello();n d.addSomething();n return 0;n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ Interview Questions

What is Boyce Codd Normal form?

1 Answers   IBS,


Can we call C++ OOPS? and Why

1 Answers  


What is a virtual function in C++?

1 Answers   C DAC,


What are issues if we mix new and free in C++?

1 Answers  


What do you know about Volatile keyword in C++? Explain with an example code.

1 Answers   Adobe,


How to invoke a C function using a C++ program?

1 Answers   Alter,


Explain what happens when an exception is thrown in C++.

1 Answers   Amazon,


What is the difference between public, private, and protected inheritance?

1 Answers   Amazon,


Explain why C++ is not purely Object Oriented Language

1 Answers   Aspire,


What does it mean to declare a member function as static in C++?

1 Answers   Amazon,


Explain the operator overloading feature in C++ ?

1 Answers  


What is the meaning of the following declaration: int *const *const *i?

1 Answers   Adobe,


Categories