Predict output of the following program
#include<iostream>
using namespace std;
class Base
{
public:
virtual void show() { cout<<" In Base n"; }
};
class Derived: public Base
{
public:
void show() { cout<<"In Derived n"; }
};
int main(void)
{
Base *bp = new Derived;
bp->show();
Base &br = *bp;
br.show();
return 0;
}
Where does the return statement returns the execution of the program?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
Which of the following is true about pure virtual functions?
1) Their implementation is not provided in a class where they are declared.
2) If a class has a pure virtual function, then the class becomes abstract class and an instance of this class cannot be created.
Predict the output of following program.
#include<iostream>
using namespace std;
class Base
{
public:
virtual void show() = 0;
};
class Derived : public Base { };
int main(void)
{
Derived q;
return 0;
}
When our function doesn’t need to return anything means what we will as parameter in function?
Can a constructor be virtual? Will the following program compile?
#include <iostream>
using namespace std;
class Base {
public:
virtual Base() {}
};
int main() {
return 0;
}
What is the output of the program?
#include<iostream>
using namespace std;
class Base {
public:
Base() { cout<<"Constructor: Base"<<endl; }
virtual ~Base() { cout<<"Destructor : Base"<<endl; }
};
class Derived: public Base {
public:
Derived() { cout<<"Constructor: Derived"<<endl; }
~Derived() { cout<<"Destructor : Derived"<<endl; }
};
int main() {
Base *Var = new Derived();
delete Var;
return 0;
}
Predict the output of following C++ program. Assume that there is no alignment and a typical implementation of virtual functions is done by the compiler.
#include <iostream>
using namespace std;
class A
{
public:
virtual void fun();
};
class B
{
public:
void fun();
};
int main()
{
int a = sizeof(A), b = sizeof(B);
if (a == b) cout << "a == b";
else if (a > b) cout << "a > b";
else cout << "a < b";
return 0;
}
If the user didn’t supply the user value means, then what value will it take?
Which value will it take when both user and default values are given?
If we start our function call with default arguments means, what will be proceeding arguments?
73 videos|7 docs|23 tests
|