Cpp Programming Quiz 175 – Which of the following function / type of function cannot be overloaded?
[A].Member function
[B].Static function[C].Virtual function
[D].Both B and C
Answer: Option C
Answer: Option C
#include
class Base
{
public:
char S, A, M;
Base(char x, char y)
{
S = y - y;
A = x + x;
M = x * x;
}
Base(char, char y = 'A', char z = 'B')
{
S = y;
A = y + 1 - 1;
M = z - 1;
}
void Display(void)
{
cout<< S << " " << A << " " << M << endl;
}
};
class Derived : public Base
{
char x, y, z;
public:
Derived(char xx = 65, char yy = 66, char zz = 65): Base(x)
{
x = xx;
y = yy;
z = zz;
}
void Display(int n)
{
if(n)
Base::Display();
else
cout<< x << " " << y << " " << z << endl;
}
};
int main()
{
Derived objDev;
objDev.Display(0-1);
return 0;
}
[A].A A A
[B].A B A
[C].A B C
[D].Garbage Garbage Garbage
Answer: Option A
#include
#include
class BixString
{
char x[50];
char y[50];
char z[50];
public:
BixString()
{ }
BixString(char* xx)
{
strcpy(x, xx);
strcpy(y, xx);
}
BixString(char *xx, char *yy = " C++", char *zz = " Programming!")
{
strcpy(z, xx);
strcat(z, yy);
strcat(z, zz);
}
void Display(void)
{
cout<< z << endl;
}
};
int main()
{
BixString objStr("Learn", " Java");
objStr.Display();
return 0;
}
[A].Java Programming!
[B].C++ Programming!
[C].Learn C++ Programming!
[D].Learn Java Programming!
Answer: Option D
#include
struct Bix
{
short n;
};
int main()
{
Bix b;
Bix& rb = b;
b.n = 5;
cout << b.n << " " << rb.n << " ";
rb.n = 8;
cout << b.n << " " << rb.n;
return 0;
}
[A].It will result in a compile time error.
[B].The program will print the output 5 5 5 8.
[C].The program will print the output 5 5 8 8.
[D].The program will print the output 5 5 5 5.
Answer: Option C
#include
int i, j;
class IndiaBix
{
public:
IndiaBix(int x = 0, int y = 0)
{
i = x;
j = x;
Display();
}
void Display()
{
cout<< j <<" ";
}
};
int main()
{
IndiaBix objBix(10, 20);
int &s = i;
int &z = j;
i++;
cout<< s-- << " " << ++z;
return 0;
}
[A].The program will print the output 0 11 21.
[B].The program will print the output 10 11 11.
[C].The program will print the output 10 11 21.
[D].The program will print the output 10 11 12.
Answer: Option B
Answer: Option A
#include
class BixTeam
{
int x, y;
public:
BixTeam(int xx)
{
x = ++xx;
}
void Display()
{
cout<< --x << " ";
}
};
int main()
{
BixTeam objBT(45);
objBT.Display();
int *p = (int*)&objBT;
*p = 23;
objBT.Display();
return 0;
}
[A].45 22
[B].46 22
[C].45 23
[D].46 23
Answer: Option A