-
What is the output of this program?
#include <iostream>
using namespace std;
template<typename T>class Example
{
public:
T var;
Example(T k)
{
this->var = k;
}
void test()
{
cout << var << endl;
}
};
class Child : public Example<char>
{
public:
Child(): Example<char>( 0 )
{
}
Child(char ch): Example<char>( ch )
{
}
void test2()
{
test();
}
};
int main()
{
Example <int> obj0( 50 );
Child obj1( 'Z' );
obj0.test();
obj1.test();
return 0;
}
-
- 50
- Z
50 - 50
Z - Z
- None of above
Correct Option: C
In this program, We are passing the values by using the template inheritance and printing it.