OOPS
August 29, 2024OOPS
August 29, 2024OOPS
|
Question 147
|
Give the output
#include
using namespace std;
class Base
{
Public:
int x,y;
Public:
Base(int i, int j)
{
x=i;y=j;
}
};
class Derived:public Base
{
public:
Derived(int i,int j):x(i),y(j){}
void print()
{
cout<<x<<""<<y;
};
int main(void)
{
Derived q(10,10);
q.print();
return 0;
}
</x<<""<<y;
#include
using namespace std;
class Base
{
Public:
int x,y;
Public:
Base(int i, int j)
{
x=i;y=j;
}
};
class Derived:public Base
{
public:
Derived(int i,int j):x(i),y(j){}
void print()
{
cout<<x<<""<<y;
};
int main(void)
{
Derived q(10,10);
q.print();
return 0;
}
</x<<""<<y;
|
1010
|
|
|
compile error
|
|
|
00
|
|
|
None of the option
|
Question 147 Explanation:
We can’t directly assign the base class members by using initializer list in the derived class
We should call the base class constructor in order to initialize base class members.
We should call the base class constructor in order to initialize base class members.
Correct Answer: B
Question 147 Explanation:
We can’t directly assign the base class members by using initializer list in the derived class
We should call the base class constructor in order to initialize base class members.
We should call the base class constructor in order to initialize base class members.
