Classes & Objects
- Which of the following can derived class inherit?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
both members & function
- Where is the derived class is derived from?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Because derived inherits functions and variables from base.
- Pick out the correct statement.
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Destructors are automatically invoked when a object goes out of scope or when a dynamically allocated object is deleted. Inheritance does not change this behavior. This is the reason a derived destructor cannot invoke its base class destructor.
- What is the output of this program?
#include <iostream>
using namespace std;
class Example
{
public:
Example()
{
cout << "N::N()" << endl;
}
Example( Example const & )
{
cout << "N::N( N const & )" << endl;
}
Example& operator=( Example const & )
{
cout << "N::operator=(N const &)" << endl;
}
};
Example function()
{
Example temp;
return temp;
}
int main()
{
Example p = function();
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
As we are passing the object without any attributes it will return as N::N().
- What is the output of this program?
#include <iostream>
using namespace std;
class First
{
public:
First(int num1 )
{
cout << num1 <<" ";
}
};
class Second: public First
{
public:
Second(int num1, double num2)
: First(num1)
{
cout << num2 <<" ";
}
};
class Third: public Second
{
public:
Third(int num1, double num2, char ch)
: Second(num1, num2)
{
cout <}
};
int main()
{
Third object(6, 5.35, 'I');
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
In this program, We are passing the value and manipulating by using the derived class.