Design Of Class Hierarchies(C++ Programming ) Questions and Answers
Explanation:-
Answer: Option C. -> class name : access specifer class nameNone.
Explanation:-
Answer: Option B. -> create a hierarchy of classesNone.
Question 3.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
class BaseClass
4.
{
5.
public:
6.
virtual void myFunction()
7.
{
8.
cout myFunction();
39.
return 0;
40.
}
- 123
- 12
- 213
- 321
Explanation:-
Answer: Option A. -> 123We are passing the objects and executing them in a certain order and we are printing the program flow.
Output:
$ g++ des3.cpp
$ a.out
123
Question 4.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
class BaseClass
4.
{
5.
int x;
6.
public:
7.
void setx(int n)
8.
{
9.
x = n;
10.
}
11.
void showx()
12.
{
13.
cout
- 10
- 20
- 1020
- None of the mentioned
Explanation:-
Answer: Option C. -> 1020In this program, We are passing the values from the main class and printing it on the inherited classes.
Output:
$ g++ des2.cpp
$ a.out
1020
Explanation:-
Answer: Option B. -> Deriving a class from more than one direct base classIn multiple inheritance, We are able to derive a class from more than one base class.
Explanation:-
Answer: Option C. -> 40In this program, We are multiplying the value 10 and 4 by using inheritance.
Output:
$ g++ des.cpp
$ a.out
40
Explanation:-
Answer: Option C. -> 3There are three types of classes. They are abstract base classes, concrete derived classes,
standalone classes.
Explanation:-
Answer: Option A. -> Overriding refers to a derived class function that has the same name and signature as a base class virtual function.None.
Explanation:-
Answer: Option B. -> 2Class hierarchies promote reuse in two ways. They are code sharing and interface sharing.
Explanation:-
Answer: Option A. -> publicIf we invoked the interface as public means, We can access the program from other programs also.